why are functions greater than numbers?

Dan Stromberg drsalists at gmail.com
Mon Jan 24 17:40:45 EST 2011


On Mon, Jan 24, 2011 at 1:51 PM, Alan <alan.isaac at gmail.com> wrote:
> Why do function objects compare in this way to numbers?
> Thanks,
> Alan Isaac
>
>
>>>> def f(): return
> ...
>>>> f>5
> True
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

They shouldn't, but did in 2.x, and no longer do in 3.x:

$ /usr/local/cpython-3.1/bin/python3
cmd started 2011 Mon Jan 24 02:39:50 PM
Python 3.1.2 (r312:79147, Aug 18 2010, 18:21:44)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def f():
...    return 'abc'
...
>>> f > 5
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: function() > int()
>>>



More information about the Python-list mailing list