Weird expression result

George Sakkis george.sakkis at gmail.com
Mon Aug 18 18:28:37 CEST 2008


On Aug 18, 12:04 pm, Peter Otten <__pete... at web.de> wrote:

> George Sakkis wrote:
> > I'm probably missing something obvious but I can't put my finger on
> > it:
>
> >>>> (3 in [3]) == True
> > True
>
> >>>> 3 in ([3] == True)
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in <module>
> > TypeError: argument of type 'bool' is not iterable
>
> >>>> 3 in [3] == True
> > False
>
> > How/why does the last one evaluate to False ?
>
> > George
>
> This works just like a < b < c:
>
> >>> 3 in [3] and [3] == True
>
> False
>
> Peter


Argh, you're right! I think chaining makes sense only for comparison
operators, for anything else it's not obvious. That came up from a
real bug by the way, it's not made up.

George



More information about the Python-list mailing list