In [32]: object() > 0
Out[32]: True
In fact, it's greater than any integer I've tried.
Because Python 2.x tried to make available comparison between objects of different types (even if they do not make sense).
It was fixed on Python 3:
>>> object() > 0
Traceback (most recent call last):
File "<pyshell#320>", line 1, in <module>
object() > 0
TypeError: unorderable types: object() > int()
The order used in Python 2.x:
None < Numbers < [Other types in alphabetical order]
Numbers are: int
, bool
and float
but not complex
because they can't be compared
Also, objects from old style classes (named instance
objects) stay between None
and Numbers
for some odd reason.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With