None in comparison

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Fri Jul 18 03:01:12 EDT 2008


On Thu, 17 Jul 2008 23:52:13 -0700, r.grimm wrote:

> Hello,
> I'm a little confused about None in comparison.
> 
>>>> id ( None )
> 3086100672L
>>>> id ( 1 )
> 134541104
>>>> None < 1
> True
>>>>
> 
> I thought, the id of the object is the last comparison criterion.

Obviously that expectation is false.  The result of a comparison between
different types, with no `__cmp__()` method that says otherwise, is a
arbitrarily but consistent ordering by type.  The language doesn't even
guarantee that it must be consistent in different runs of the same program
in the same interpreter, just within one run.

So if you plan to rely on such implementation details, your program is
broken.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list