Possible Duplicate:
Order of syntax for using ‘not’ and ‘in’ keywords
My TA claims that e not in c
doesn't always yield the same results as not e in c
(he didn't give an explanation why though). I've never personally seen the second form in anyone's code (except his and books explaining that the two are equivalent) and never seen the two to differ in behavior so I'm suspicious of this claim. Not having found anything on it through Google I decided to come here.
So does anyone have any information about any case in which the behavior of the two differs?
They are exactly same, as both actually apply the not in
comparision:
In [25]: def func():
'e' not in 'bee'
....:
....:
In [27]: def func1():
not 'e' in 'bee'
....:
....:
In [29]: dis.dis(func)
2 0 LOAD_CONST 1 ('e')
3 LOAD_CONST 2 ('bee')
6 COMPARE_OP 7 (not in)
9 POP_TOP
10 LOAD_CONST 0 (None)
13 RETURN_VALUE
In [30]: dis.dis(func1)
2 0 LOAD_CONST 1 ('e')
3 LOAD_CONST 2 ('bee')
6 COMPARE_OP 7 (not in)
9 POP_TOP
10 LOAD_CONST 0 (None)
13 RETURN_VALUE
They're identical. not
has a lower precedence than in
, so not x in y
is parsed as not (x in y)
, which returns the opposite of in
, which is what not in
does.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With