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

<不支持str实例和int实例之间的对比

birth是str类型

2000是int类型

所以无法对比,报错

1 birth = input(‘birth: ‘)
2 if birth < 2000:
3     print(‘00前‘)
4 else:
5     print(‘00后‘)

修改为:

1 s = input(‘birth: ‘)
2 birth = int(s)
3 if birth < 2000:
4     print(‘00前‘)
5 else:
6     print(‘00后‘)

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

原文地址:https://www.cnblogs.com/denggelin/p/8946618.html

时间: 2024-07-30 05:14:28

TypeError: '<' not supported between instances of 'str' and 'int'的相关文章

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

当我们编程时,有时会出现如下错误:TypeError: '>' not supported between instances of 'str' and 'int' 如下图: 这是因为input()返回的数据类型是str类型,不能直接和整数进行比较,必须先把str转换成整型,使用int()方法:age = int(input ("请输入你的年龄:")) 改正之后为: 这样程序就达到了预期的效果了 python的强制转换(当出现 not supported between inst

python3报错:TypeError: can&#39;t concat bytes to str

有时会报错这个:TypeError: Can't convert 'bytes' object to str implicitly 解决方法:使用字节码的decode()方法. 示例: str = 'I am string' byte = b' I am bytes' s = str + byte print(s) 这时会报错:TypeError: Can't convert 'bytes' object to str implicitly 解决方法: s = str + byte.decode

TypeError: the JSON object must be str, not &#39;bytes&#39;

json.loads(json_data)报错 修改为json.loads(json_data.decode())即可 一些修改为load什么的方法会带来新的报错… 直接添加decode()解决 描述 Python decode() 方法以 encoding 指定的编码格式解码字符串.默认编码为字符串编码. 语法 decode()方法语法: str.decode(encoding='UTF-8',errors='strict') 参数 encoding -- 要使用的编码,如"UTF-8&quo

总结:TypeError: must be real number, not str

TypeError: must be real number, not str 用了占位符%f,要注意参数要是数字类型的,而不能是str类型的 原文地址:https://www.cnblogs.com/yayazhang221/p/12060418.html

python产生错误:can only concatenate str (not &quot;int&quot;) to str

代码为: #!/usr/bin/python # _*_ coding:utf-8_*_ # print("hello world!") name = input("name:") age = int(input("age:")) print(type(age)) #print(type(age), type(str(age))) home = input("home:") print(type(home)) info3=''

atoi():str转int

描述 C 库函数 int atoi(const char *str) 把参数 str 所指向的字符串转换为一个整数(类型为 int 型). 声明 下面是 atoi() 函数的声明. int atoi(const char *str) 参数 str -- 要转换为整数的字符串. 返回值 该函数返回转换后的长整数,如果没有执行有效的转换,则返回零. 实例 下面的实例演示了 atoi() 函数的用法. #include <stdio.h> #include <stdlib.h> #inc

python str转int

method 1 In [18]: str1 = '123' In [19]: a = int(str1) In [20]: a Out[20]: 123 In [21]: type(a) Out[21]: int method 2 In [22]: str1 = '123' In [23]: import string In [24]: a = string.atoi(str1) In [25]: a Out[25]: 123 In [26]: type(a) Out[26]: int

Python--my first try!

我所用的编译器是:Python 3.6.0 我之所以在一开始就说我的编译器是因为不同的编译器,不同的版本在代码的写法上会有一些区别! 比如:在我所用的版本3中print的用法是Print ("hello world!") ,而在之前的版本2中则是print "hello world!",不需要括号. >>> print ("The secret number is:",secret)The secret number is: 3

【函数】02、匿名函数、生成器、高阶函数

一.匿名函数 1.定义 语法格式: lambda args:expression args:以逗号分隔的参数列表 expression:用到args中各参数的表达式 lambda定义的代码必须是合法的表达式,不能出现多条件语句(可使用if的三元表达式)和非表达式,如for和while等 lambda的首要用途是指定短小的回调函数 lambda将返回一个函数而不是将函数赋值给某变量名 In [77]: lambda x: x+1 Out[77]: <function __main__.<lamb