# 有关数据类型的判断

``````number = input("\n\t Enter a integer number, and I will tell you if it is even or odd: " + "\n\t ")
if not (type(number) is int):
number = input("\n\t Please input a integer. " + "\n\t ")
number = int(number)``````

`input` 返回的是字符串 `str`, 而非`int``float`, 所以`not (type(number) is int)`永远为`True`

``````>>> number = input("\n\t Enter a integer number, will tell you even or odd: " + "\n\t ")

Enter a integer number, will tell you even or odd:
123
>>> type(number)
<class 'str'>
>>> number = input("\n\t Enter a integer number, will tell you even or odd: " + "\n\t ")

Enter a integer number, will tell you even or odd:
1.23
>>> type(number)
<class 'str'>
>>> type(number) is int
False
>>> type(number) is float
False
>>> type(number) is str
True
>>> not (type(number) is int)
True``````
2周前 评论
Jason990420 （作者） 2周前
nizuitianla （楼主） 2周前
nizuitianla （楼主） 2周前

`input` 返回的是字符串 `str`, 而非`int``float`, 所以`not (type(number) is int)`永远为`True`

``````>>> number = input("\n\t Enter a integer number, will tell you even or odd: " + "\n\t ")

Enter a integer number, will tell you even or odd:
123
>>> type(number)
<class 'str'>
>>> number = input("\n\t Enter a integer number, will tell you even or odd: " + "\n\t ")

Enter a integer number, will tell you even or odd:
1.23
>>> type(number)
<class 'str'>
>>> type(number) is int
False
>>> type(number) is float
False
>>> type(number) is str
True
>>> not (type(number) is int)
True``````
2周前 评论
Jason990420 （作者） 2周前
nizuitianla （楼主） 2周前
nizuitianla （楼主） 2周前