Why does this work: 5<"five" ?

Ingo Linkweiler ingo.linkweiler at icc-computer.de
Fri May 31 19:16:05 EDT 2002


Hi,

today I found a really annoying "feature" of Python:

>>> 5<"five"
1

Why can I compare values of any type ?

>>> class x:
...  pass
>>> 5==x
0
>>> 5<x
1

But when using "coerce", I get an error:
>>> coerce(5,"five")
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
TypeError: number coercion failed

So what is the interpreter doing here?

Ingo





More information about the Python-list mailing list