【Python】关于键盘键入值、str的与或非问题?【报错:TypeError: unsupported operand type(s) for |: 'str' and 'str'】

参考

 

【报错:TypeError: unsupported operand type(s) for |: 'str' and 'str'】

  在进行键入值比较的时候,想要用“或”运算符对比较结果进行或运算作为 if语句 的判断条件。

  结果报错了,说“这个或运算符号 ‘’|‘’ 不能用在‘str‘ 类型之间”????WTF?

ctnue = raw_input('Do you want to check the next one? T/F :')
#    屏显为如下所示:     并且键入了字符“T”
#    Do you want to check the next one? T/F :>? T
#
#    好的接下来我要比对以下键入字符的值,并做或运算
 ctnue=='T' | ctnue=='f'
#    屏显为:报错
#    TypeError: unsupported operand type(s) for |: 'str' and 'str'
#    WTF???
#    好吧改为:
(ctnue=='T') | (ctnue=='f')
#    屏显为:
#    True
#    解决……还有没有其他办法?额再说

 

posted @ 2019-03-11 12:10  anno_ym雨  阅读(12826)  评论(0编辑  收藏  举报