Skip to content

Instantly share code, notes, and snippets.

@skyl skyl/gist:1410323
Created Nov 30, 2011

Embed
What would you like to do?
Python order of operations gotcha
In [61]: l
Out[61]: [1, 2, 3, False]
In [62]: i
Out[62]: 1
In [63]: not i in l
Out[63]: False
In [64]: (not i) in l
Out[64]: True
In [65]: i not in l
Out[65]: False
In [66]: not i in l == i not in l
Out[66]: True
In [67]: i not in l == not i in l
------------------------------------------------------------
File "<ipython console>", line 1
i not in l == not i in l
^
SyntaxError: invalid syntax
In [68]: i not in l == (not i in l)
Out[68]: False
In [69]: (i not in l) == (not i in l)
Out[69]: True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.