python 3 bytes比较

问题代码:

if ch>=b'0'

(Pdb) type(ch)
<class 'bytes'>
(Pdb) type(b'0')
<class 'bytes'>

TypeError: '>=' not supported between instances of 'bytes' and 'str'
请问该如何解决?

需要完整代码吗

阅读 5.6k
1 个回答

都转化为int类型进行比较

num = int(b'0')
ch = int(ch)
if ch >= num:
    pass
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题