(a不在b中)和(不在b中)之间的差异.蟒蛇

Ale*_*lex 3 python

嗨,有人可以阐明在Python中使用"in"运算符的机制.

我现在正在处理以下示例:

print ('a' not in ['a', 'b'])  # outputs False
print (not 'a' in ['a', 'b'])  # outputs False   --   how ???

print ('c' not in ['a', 'b'])  # outputs True
print (not 'c' in ['a', 'b'])  # outputs True


print (not 'a')   # outputs False
# ok is so then...
print (not 'a' in ['b', False])   # outputs True --- why ???
Run Code Online (Sandbox Code Playgroud)

我现在很奇怪它是如何如此.如果有人知道,请分享您的知识.谢谢=)

Ign*_*ams 8

in优先级高于not.因此,执行包容检查,然后在需要时否定结果.'a'不存在['b', False],结果False被否定导致True.