[Baypiggies] What is happening here with true/false comparisons

Brent Pedersen bpederse at gmail.com
Mon Jan 25 22:26:21 CET 2010


http://docs.python.org/reference/expressions.html#summary

so == and 'in' have the same precedence. so your statement is equivalent to:

  >>> ((a in alist) == b) in alist



On Mon, Jan 25, 2010 at 1:12 PM, Max Slimmer <max at theslimmers.net> 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
>>>>
>
> 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