The canonical question on the difference between not x in y
and x not in y
states that these two are equivalent in implementation (in CPython). The operator precedence rules state that the Boolean not
has higher precedence than in
. So shouldn't not x in y
be implemented to be equivalent to (not x) in y
?
Consider
x = False
list2 = ['a']
not x in list2
Out[19]: True
(not x) in list2
Out[20]: False
I would have expected second last statement to be False
, if I'm understanding the precedence rules correctly.