returning True, False or None

Steven Bethard steven.bethard at gmail.com
Fri Feb 4 15:13:08 EST 2005


Fredrik Lundh wrote:
> Steven Bethard wrote:
>> Raymond Hettinger wrote: 
>>>
>>> return max(lst)
>>
>> Very clever!  Thanks!
> 
> too clever.  boolean > None isn't guaranteed by the language specification:

Yup.  I thought about mentioning that for anyone who wasn't involved in 
the previous thread discussing this behavior, but I was too lazy.  ;) 
Thanks for pointing it out again.

This implementation detail was added in Python 2.1a1, with the following 
note[1]:

"The outcome of comparing non-numeric objects of different types is
not defined by the language, other than that it's arbitrary but
consistent (see the Reference Manual).  An implementation detail changed
in 2.1a1 such that None now compares less than any other object.  Code
relying on this new behavior (like code that relied on the previous
behavior) does so at its own risk."

Steve

[1] http://www.python.org/2.1/NEWS.txt



More information about the Python-list mailing list