热线电话:13121318867

登录
2021-03-26 阅读量: 1253
python报错 TypeError: '<'not supported between instances of 'str' and 'int'

问:

python报错 TypeError: '<'not supported between instances of 'str' and 'int'

image.png


答:

这是因为在python中input()语句输入的内容默认为字符串类型,而字符串类型的变量与整数型变量

之间不支持‘<’比较操作,因此会出现报错。解决方法是先将input()的内容转换为整数型,再进行比较,如下:

image.png


99.9374
0
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子