Operator precedence 2.x, 3.x. The precedence of not
is lower than that of in
. So it is equivalent to:
>>> not ((True) in [False, True])
False
This is what you want:
>>> (not True) in [False, True]
True
As @Ben points out: It's recommended to never write not(True)
, prefer not True
. The former makes it look like a function call, while not
is an operator, not a function.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…