None is negative?
Ned Deily
nad at acm.org
Tue Aug 3 16:30:08 EDT 2010
In article
<AANLkTim1WMz-UJxuK4nO6b85hiidyQHaNu6ACYCCDap+ at mail.gmail.com>,
wheres pythonmonks <wherespythonmonks at gmail.com> wrote:
> I did the google search... I must be blind as I don't see any hits...
>
> None is negative in Python? (v2.6)
>
> http://www.google.com/search?ie=UTF-8&q=%22none+is+negative%22+python
>
> >>> if None < -9999999.99: print "hi"
>
> hi
> >>>
>
> >>> if -9999999 > None: print "hi"
>
> hi
> >>>
>
> Is there a way to have the comparison raise an exception?
This is a well-known wart in Python 2. The behavior has been changed in
Python 3.
$ python
Python 2.6.5 (r265:79063, Jul 15 2010, 01:53:46)
[GCC 4.2.1 (Apple Inc. build 5659)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> None < -9.9
True
>>>
$ python3
Python 3.1.2 (r312:79360M, Mar 24 2010, 01:33:18)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> None < -9.9
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unorderable types: NoneType() < float()
>>>
--
Ned Deily,
nad at acm.org
More information about the Python-list
mailing list