comparing booleans
Duncan Booth
me at privacy.net
Thu Jan 29 15:31:33 CET 2004
Dang Griffith <noemail at noemail4u.com> wrote in
news:eaa90cc908c7a217f0d6475e41c7622d at news.teranews.com:
> Interestingly, and I'm not sure why:
>>>> (True != True) != True
> True
>>>> True != (True != True)
> True
>>>> True != True != True
> False
You can chain comparison operators in Python. e.g.
a < b < c
is the same as:
(a < b) && (b < c)
except that if b is an expression the first form evaluates it exactly once
whereas the second form evaluates it either once or twice.
You can use any comparison operators in this form, so your True!=True!=True
is just shorthand for:
(True!=True) && (True!=True)
which is in turn equivalent to:
False && (True!=True)
and 'False && anything' gives False.
More information about the Python-list
mailing list