码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-09-16 18:41:19      阅读:23162      评论:0      收藏:0      [点我收藏+]

标签:ted   port   数据   log   es2017   直接   logs   ges   转换   

当我们编程时,有时会出现如下错误: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' 的错误时)

标签:ted   port   数据   log   es2017   直接   logs   ges   转换   

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

(3)
(27)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!