【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
#    解決……還有沒有其他辦法?額再說

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM