Marc 'BlackJack' Rintsch wrote:
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.
And in 3.0 such arbitrary comparisons are gone.
>>> None < 1
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
None < 1
TypeError: unorderable types: NoneType() < int()
--
http://mail.python.org/mailman/listinfo/python-list