当前位置: 移动技术网 > IT编程>脚本编程>Python > Python报错TypeError: '<' not supported between instances of 'str

Python报错TypeError: '<' not supported between instances of 'str

2018年03月15日  | 移动技术网IT编程  | 我要评论

郭德纲单口相声大全,刘伯温预言,修真者玩转无限恐怖

1 n = input()
2 if n>=100:print(int(n)/10)
3 else:print(int(n)*10)

报错内容:

 

Traceback (most recent call last):
  File "1.py", line 12, in <module>
    if n>=100:print(int(n)/10)
TypeError: '>=' not supported between instances of 'str' and 'int'

***Repl Closed***

 

 

分析:input()返回的数据类型是str,不能直接和整数进行比较,必须先把str换成整数,使用int()方法

          因此,将input变量转换为int型即可。

1 n = input()
2 n = int(n)
3 if n>=100:print(int(n)/10)
4 else:print(int(n)*10)

 

 

          

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网