[portland] fun with comparison operators and booleans

Dylan Reinhardt python at dylanreinhardt.com
Tue Jan 26 01:22:14 CET 2010


There was a fun thread on Baypiggies today, where someone asked:

----
Can anyone explain the following:

>>>* a = 1*>>>* b = 2*>>>* alist = [5,6]*>>>* print a in alist*False

>>>* a in alist == b in alist*False
>>>* a in alist == a in alist*False
>>>* bool(a in alist) == bool(b in alist)      # this does what we expect*True
>>>* c = 5*>>>* c in alist == c in alist*False

----

After some guesses and discussion came this cool answer:

http://mail.python.org/pipermail/baypiggies/2010-January/006139.html

Well worth a read...

Dylan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/portland/attachments/20100125/b8eae0aa/attachment.htm>


More information about the Portland mailing list