Why is None <= 0

Gary Herron gherron at islandtraining.com
Fri Apr 25 14:40:23 EDT 2008


Gregor Horvath wrote:
> Hi,
>
> >>> None <= 0
> True
>
> Why?
> Is there a logical reason?
>
> Gregor
> -- 
> http://mail.python.org/mailman/listinfo/python-list

In early Python, the decision was made that the comparison of *any* two 
objects was legal and would return a consistent result.  So objects of 
different types will compare according to an ordering on their types (an 
implementation dependent, unspecified, but consistent ordering), and 
objects of the same type will be compared according to rules that make 
sense for that type.

Other implementations have the right to compare an integer and None 
differently, but on a specific implementation, the result will not change.

Python 3 will raise an exception on such comparisons.

Gary Herron




More information about the Python-list mailing list