Curious relation

Dan Bishop danb_83 at
Thu Apr 24 07:08:49 CEST 2008

On Apr 23, 11:51 pm, Greg J <greg.ja... at> wrote:
>  I was reading the programming Reddit tonight and came across this
> (
> >>> ([1]>2)==True
> True
> >>> [1]>(2==True)
> True
> >>> [1]>2==True
> False
> Odd, no?
> So, can anyone here shed light on this one?

A long time ago, it wasn't possible for comparison operators to raise
exceptions, so it was arbitrarily decided that numbers are less than
strings.  Thus, [1]>2 and [1]>False.  This explains your first two

For the third, remember that the comparison operators are chained, so
a>b==c means (a>b) and (b==c).  Since 2==True is false, so is the
entire expression.

In Python 3.0, all three of these expressions will raise a TypeError.

More information about the Python-list mailing list