why are functions greater than numbers?

MRAB python at mrabarnett.plus.com
Mon Jan 24 17:56:48 EST 2011


On 24/01/2011 21:51, Alan wrote:
> Why do function objects compare in this way to numbers?
> Thanks,
> Alan Isaac
>>>>>> def f(): return
> ...
>>>> f>5
> True
>In Python 2 any object can be compared in this way to any other. The
result is arbitrary but consistent.
In Python 3 that has changed because in practice it's more trouble than
it's worth:
 >>> def f(): return
 >>> f>5
Traceback (most recent call last):
 File "<pyshell#2>", line 1, in <module>
 f>5
TypeError: unorderable types: function() > int()
It's usually a good sign that there's a bug somewhere.


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /