On Thu, 27 Sep 2007 17:06:30 +0000, Duncan Booth wrote: > Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> 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.
Aaah *enlightenment*, I'm using this for range checks like in the docs, but it wasn't obvious to me in this case. Thanks. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list