Why does this work: 5<"five" ?
Jiri Baum
jiri at baum.com.au
Fri May 31 23:55:03 EDT 2002
Ingo Linkweiler:
> today I found a really annoying "feature" of Python:
>>>> 5<"five"
> 1
> Why can I compare values of any type ?
...
> So what is the interpreter doing here?
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.
Jiri
--
Jiri Baum <jiri at baum.com.au> http://www.csse.monash.edu.au/~jirib
MAT LinuxPLC project --- http://mat.sf.net --- Machine Automation Tools
More information about the Python-list
mailing list