想知道是否有人可以帮助我。我需要检查成员是否等于3个不同的字符串。我尝试过使用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"
。
答案 0 :(得分:3)
您只需要一次in
测试:
for member in list:
if member not in ('a', 'b', 'c'):
print member
答案 1 :(得分:0)
如果您希望代码正常工作,您只需要将'或'替换为'和'。尽管如此,Rohit Jain的答案仍然是表达同样事情的更好方式。