[Baypiggies] What is happening here with true/false comparisons
Kevin Wright
akwright at mac.com
Mon Jan 25 22:28:11 CET 2010
On Jan 25, 2010, at 1:12 PM, Max Slimmer wrote:
> 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
> >>>
I assume it has to do with precedence:
>>> (c in alist) == (c in alist)
True
Using the parentheses insures you are making the correct comparison
>
> max
> _______________________________________________
> Baypiggies mailing list
> Baypiggies at python.org
> To change your subscription options or unsubscribe:
> http://mail.python.org/mailman/listinfo/baypiggies
More information about the Baypiggies
mailing list