[Python-3000] None in Comparisons

Antoine Pitrou solipsis at pitrou.net
Wed Nov 12 00:09:14 CET 2008


M.-A. Lemburg <mal <at> egenix.com> writes:
> 
> >>> None > None
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: unorderable types: NoneType() > NoneType()
> >>> None != None
> False
> 
> Two values that compare equal to each other (and are in fact identical),
> yet cannot be compared less-than or greater-than.

The error message is clear: "unorderable types". Having some types support an
equivalence relation (e.g. "equality") but no intuitive total order relation is
hardly a surprise. As someone said, complex numbers are an example of that (not
only in Python, but in real life).

> This would make sense if you think of None as meaning "anything
> and/or nothing", since the left side None could stand for
> a different None than the right one, but then you could apply the
> same logic to inf:

inf is a float instance, and as such supports ordering. I don't see how it
invalidates None *not* supporting an order relation, since None isn't a float
instance and doesn't pretend to be usable as a number (or as anything supporting
ordering, for that matter).





More information about the Python-3000 mailing list