On Apr 23, 11:51 pm, Greg J <[EMAIL PROTECTED]> wrote: > I was reading the programming Reddit tonight and came across this > (http://reddit.com/info/6gwk1/comments/): > > >>> ([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 examples. 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. -- http://mail.python.org/mailman/listinfo/python-list