Comparing None and ints

Xavier Ho contact at xavierho.com
Tue Jan 17 01:47:39 EST 2012


Hello,

I discovered this strange property by accident:

Python 2.7.2 (default, Nov 21 2011, 17:25:27)
[GCC 4.6.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> None < 0
True
>>> None == 0
False
>>> None > 0
False
>>> int(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: int() argument must be a string or a number, not 'NoneType'

What was the rationale behind this design?  Specifically, (None < 0)
== Trueand(None == 0) == False
?

Personally I would have expected an exception on all tests above.

Cheers,
Xav
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120117/ba41efde/attachment.html>


More information about the Python-list mailing list