TypeError: ‘>=‘ not supported between instances of ‘str‘ and ‘int‘

今天遇到一个bug

TypeError: '>=' not supported between instances of 'int' and 'str'

后来了解到 input 输入的是str类型的

要想实现>= 就要换成int 类型

改正:

age = int(input("请输入你的年龄:"))
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用\[1\]:Python报错:TypeError: ‘>=’ not supported between instances of ‘str’ and ‘float’ 报错原因:字符串(str)和浮点数(float)不能进行大于等于(>=)的比较操作 解决办法:确保比较的两个值的类型相同,可以使用类型转换将字符串转换为浮点数,然后再进行比较操作。 引用\[2\]:TypeError: ‘>=’ not supported between instances of ‘str’ and ‘float’ num = input("请输入数字:") if float(num) >= 10.0: print("大于等于10") else: print("小于10") 在第二行这里,字符串和浮点数进行大于等于的比较操作导致报错。 引用\[3\]:原因是Python中字符串(str)和浮点数(float)是不同的数据类型,不能直接进行大于等于的比较操作。要解决这个问题,可以使用float()函数将字符串转换为浮点数,然后再进行比较操作。例如,可以使用float(num) >= 10.0来比较一个字符串和一个浮点数。 #### 引用[.reference_title] - *1* *2* [TypeError: ‘’ not supported between instances of ‘str’ and ‘int’](https://blog.csdn.net/aeadobe3/article/details/126090605)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Python出错TypeError: ‘‘ not supported between instances of ‘int‘ and ‘NoneType](https://blog.csdn.net/hsgrass37301/article/details/123034778)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值