簡體   English   中英

在python中比較2條錯誤語句的正確方法是什么?

[英]What is the correct way to compare 2 false statements in python?

給定示例代碼:

        if not token == '-' or token == '+':
        print token

檢測到-,但未檢測到+

如果我將代碼編輯為:

        if not token == '-' or not token == '+':
        print token

均未檢測到。

最簡單的方法:

if token not in '-+':

但是傳統上,將not放在某些問題之外...

if not (token == '-' or token == '+'):

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM