Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
只是想知道是否有人可以帮助我。我需要检查成员是否等于 3 个不同的字符串。我试过 use or,但没有成功。代码是:
or
list = ["a", "b", "c", "d"] for member in list: if not member == "a" or not member == "b" or not member == "c": print member
我只需要打印"d". 我只需要得到"d".
"d"
你只需要一个in测试:
in
for member in list: if member not in ('a', 'b', 'c'): print member
如果您希望您的代码正常工作,您只需要将 'or' 替换为 'and'。不过,Rohit Jain 的回答是表达同一件事的更好方式。