True of False

Duncan Booth duncan.booth at invalid.invalid
Thu Sep 27 13:06:30 EDT 2007


Marc 'BlackJack' Rintsch <bj_666 at gmx.net> wrote:

> In [268]: 'c' in a == True
> Out[268]: False
> 
> In [269]: ('c' in a) == True
> Out[269]: True
> 
> In [270]: 'c' in (a == True)
> -----------------------------------------------------------------------
> ---- 
><type 'exceptions.TypeError'>             Traceback (most recent call
>last) 
> 
> /home/bj/<ipython console> in <module>()
> 
><type 'exceptions.TypeError'>: argument of type 'bool' is not iterable
> 
> 
> What's going on there?

See http://docs.python.org/ref/comparisons.html

> Comparisons can be chained arbitrarily, e.g., x < y <= z is equivalent
> to x < y and y <= z, except that y is evaluated only once (but in both
> cases z is not evaluated at all when x < y is found to be false). 

In exactly the same way:

   'c' in a == True

is equivalent to:

   'c' in a and a == True

which is False.





More information about the Python-list mailing list