comparison with None

Gary Herron gherron at islandtraining.com
Thu Apr 19 00:46:41 CEST 2007


Alan G Isaac wrote:
>  >>> None >= 0
> False
>  >>> None <= 0
> True
>
> Explanation appreciated.
>
> Thanks,
> Alan Isaac
>   
So that we can sort lists of objects, even when the objects of are
different types, Python guarantees to supply a unique and consistent
ordering of any two objects.   The definition of Python does not specify
what that ordering is -- that's implementation dependent --  but any two
objects of any two types *do* have an ordering and that ordering will
always be the same.

So in your implementation None is less than 0 (and probably less than
any integer).   Given that, your two observations above are consistent.

Gary Herron




More information about the Python-list mailing list