Why does this work: 5<"five" ?
kragen at pobox.com
Mon Jun 3 06:03:52 CEST 2002
Jiri Baum <jiri at baum.com.au> writes:
> It's documented that way. When comparing values of different types, you get
> an arbitrary (but fixed) ordering. I think the docs say it can change from
> version to version.
> You'll note that 5>"five" gives you a 0.
> This means you can do things like binary search trees without worrying
> about how to sort disparate values.
That's what I thought, too, but (in 2.1.1):
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: cannot compare complex numbers using <, <=, >, >=
So if you put complex numbers into your binary search tree, you will
Oh, enjoy this:
>>> (1,) < (2,)
>>> (1j,) < (1j,)
I'm not sure what's going on there. I thought maybe tuple comparison
did an 'is' before doing an actual comparison, but timing suggests
that it doesn't.
More information about the Python-list