How does compare work?

Inyeol Lee inyeol.lee at siimage.com
Mon Jan 26 18:57:04 EST 2004


On Mon, Jan 26, 2004 at 10:28:31PM +0100, Helmut Jarausch wrote:
> Hi,
> 
> what does Python do if two objects aren't comparable (to my opinion)
> If I've understood "Python in a Nutschell" correctly it should raise an
> exception but it doesn't do for me.
> 

>From section 5.9 in Python 2.3.3 Reference manual;
"""
The operators <, >, ==, >=, <=, and != compare the values of two
objects. The objects need not have the same type. If both are numbers,
they are converted to a common type. Otherwise,
objects of different types always compare unequal, and are ordered
consistently but arbitrarily. 

(This unusual definition of comparison was used to simplify the
definition of operations like sorting and the in and not in operators.
In the future, the comparison rules for objects of
different types are likely to change.) 
"""

-Inyeol Lee




More information about the Python-list mailing list