“如果变量不在列表中”不工作则一直返回true

时间:2013-12-13 13:59:13

标签: python if-statement return

为什么这行代码总是返回true?

def GetPlayersMove(self):
    self.move = input("Enter Rock, Paper or Scissors: ")
    if self.move.lower() not in ["rock" "paper", "scissors"]:
        print("Error")

1 个答案:

答案 0 :(得分:12)

代码遗失,

["rock" "paper", "scissors"]
#      ^

"rock" "paper"相当于"rockpaper"

>>> ["rock" "paper", "scissors"]
['rockpaper', 'scissors']
>>>

请参阅String literal concatenation