首页 > 编程语言 > 详细

python的强制转换(当出现 not supported between instances of 'str' and 'int' 的错误时)

时间:2017-09-16 18:03:42      阅读:10326      评论:0      收藏:0      [点我收藏+]

当我们编程时,有时会出现如下错误:TypeError: ‘>‘ not supported between instances of ‘str‘ and ‘int‘

如下图:

技术分享


 

 这是因为input()返回的数据类型是str类型,不能直接和整数进行比较,必须先把str转换成整型,使用int()方法:age = int(input ("请输入你的年龄:"))

 

 

 改正之后为:

技术分享

 

 这样程序就达到了预期的效果了

python的强制转换(当出现 not supported between instances of 'str' and 'int' 的错误时)

原文:http://www.cnblogs.com/xisheng/p/7531862.html

(0)
(8)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!