danb_83 at yahoo.com
Thu Apr 24 07:08:49 CEST 2008
On Apr 23, 11:51 pm, Greg J <greg.ja... at gmail.com> wrote:
> I was reading the programming Reddit tonight and came across this
> >>> (>2)==True
> >>> >(2==True)
> >>> >2==True
> 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, >2 and >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
In Python 3.0, all three of these expressions will raise a TypeError.
More information about the Python-list