Python---TypeError: '<' not supported between instances of 'str' and 'int'
2017-02-09 14:06
826 查看
根据用户输入的出生年份,判断并打印出用户是00后还是00前
此时如果直接输入1988,报错如下:
Traceback (most recent call last):
File "z.py", line 2, in <module>
if birth < 2000:
TypeError: '<' not supported between instances of 'str' and 'int'
![](http://img.blog.csdn.net/20170209140151562)
这是因为input()返回的数据类型是str,不能直接和整数进行比较,必须先把str换成整数,使用int()方法:
![](http://img.blog.csdn.net/20170209140544291)
更多iOS、Android、Python的文章,请点击:
更多Java、Unity3D的文章,请点击:
birth = input('birth:') if birth < 2000: print('00前') else: print('00后')
此时如果直接输入1988,报错如下:
Traceback (most recent call last):
File "z.py", line 2, in <module>
if birth < 2000:
TypeError: '<' not supported between instances of 'str' and 'int'
这是因为input()返回的数据类型是str,不能直接和整数进行比较,必须先把str换成整数,使用int()方法:
s = input('birth:') birth = int(s) if birth < 2000: print('00前') else: print('00后')
更多iOS、Android、Python的文章,请点击:
http://blog.csdn.net/jamiecheung
更多Java、Unity3D的文章,请点击:
http://blog.csdn.net/u010841622
相关文章推荐
- Python3.6:“猜数字游戏”TypeError: '<' not supported between instances of 'str' and 'int'
- TypeError: '<' not supported between instances of 'str' and 'int'
- TypeError: '<' not supported between instances of 'treeNode' and 'treeNode'
- '>=' not supported between instances of 'str' and 'int'
- 提示错误“'>=' not supported between instances of 'range' and 'int'”
- Python之Headers value 1 must be of type str or bytes, not <class 'int'>错误的解决
- Python初学者错误:TypeError: unsupported operand type(s) for +: 'int' and 'str'
- Python字符串与数字拼接报错解决TypeError: cannot concatenate 'str' and 'int' objects
- Python字符串与数字拼接 TypeError: cannot concatenate 'str' and 'int' objects
- Python错误:TypeError: unsupported operand type(s) for +: 'int' and 'str'
- Python:TypeError: unorderable types: int() < str()
- Python:TypeError: 'int' object is not callable
- 关于 "Uncaught TypeError: Property 'submit' of object #<HTMLFormElement> is not a function" 的解决方案
- Python 3.5 Socket TypeError: a bytes-like object is required, not 'str' 错误提示
- opencv-python cv2接口下错误TypeError: mat data type=18 is not supported
- Python 3.x Error:TypeError: a bytes-like object is required, not 'str'
- python TypeError: 'int' object is not iterable
- Python笔记002——错误TypeError: 'str' does not support the buffer interface
- TypeError: unsupported operand type(s) for +: 'int' and 'str'
- Python_bug收集_TypeError:'str' does not support the buffer interface