Skip to content

Instantly share code, notes, and snippets.

@skyl
Created November 30, 2011 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skyl/1410323 to your computer and use it in GitHub Desktop.
Save skyl/1410323 to your computer and use it in GitHub Desktop.
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