0

只是想知道是否有人可以帮助我。我需要检查成员是否等于 3 个不同的字符串。我试过 use 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".

4

2 回答 2

3

你只需要一个in测试:

for member in list:
    if member not in ('a', 'b', 'c'):
        print member 
于 2013-10-12T19:16:42.683 回答
0

如果您希望您的代码正常工作,您只需要将 'or' 替换为 'and'。不过,Rohit Jain 的回答是表达同一件事的更好方式。

于 2013-10-12T19:30:20.213 回答