>>> a=10
>>> b=input()
2
>>> print(a<b)
Traceback (most recent call last):
File "<pyshell#51>", line 1, in <module>
print(a<b)
TypeError: unorderable types: int() < str()
上面的语句在Python2里面是可以执行的,但是在Python3里面会报错。原来,Python3里面input()默认的类型是string型。可以用int()将类型转化成integer型。
>>> a=10
>>> b=input()
2
>>> print(a<int(b))
False
>>>