[Tutor] beginning to code

Jerry Hill malaclypse2 at gmail.com
Wed Sep 20 10:50:00 EDT 2017


On Tue, Sep 19, 2017 at 8:26 PM, Rick Johnson
<rantingrickjohnson at gmail.com> wrote:
> In the spirit of my last comment, i was going to say: "Or if
> `x` does not support rich comparisons", but alas, it seems that
> _all_ objects in Python support rich comparisons, even when
> it doesn't make sense to! o_O For example:
>
>     >>> False > 1
>     False
>     >>> dir > 1
>     True
>     >>> isinstance < 100
>     False
>     >>> "" >= 10
>     True
>     >>> (1,) <= 500
>     False

Rick, I'm pretty sure you already know that you're being deceptive
here.  If anyone else comes across this and doesn't already realize
it, note that Rick is complaining about behavior that changed almost a
decade ago (with the release of Python 3.0).

Here's what a modern python does with those same statements:

Python 3.5.2 (default, Aug 18 2017, 17:48:00)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> False > 1
False
>>> dir > 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: builtin_function_or_method() > int()
>>> isinstance < 100
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: builtin_function_or_method() < int()
>>> "" >= 10
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: str() >= int()
>>> (1,) <= 500
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: tuple() <= int()
>>>

-- 
Jerry



More information about the Python-list mailing list