None in comparison

R

r.grimm

Hello,
I'm a little confused about None in comparison.

I thought, the id of the object is the last comparison criterion.
Therefore, None must be greater then 1.
Where is the behaviour of the comparison defined?. In the __cmp__ of
int. Or in the global cmp Function?

Thanks in advance
Rainer
 
M

Marc 'BlackJack' Rintsch

Hello,
I'm a little confused about None in comparison.


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
 
T

Terry Reedy

Marc said:
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.Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
None < 1
TypeError: unorderable types: NoneType() < int()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,270
Messages
2,571,101
Members
48,773
Latest member
Kaybee

Latest Threads

Top