On 01.06.2013 07:47, Sarma Tangirala wrote:
I had a quick question on how string compare works. If did '1001' <= '999'
I get true. I know how the string compare works but I was wondering why it
were so. Why doesn't the string length factor into the comparison?

Because usually you are interested in the lexicographical order when you compare strings. You wouldn't expect "pear" listed before "apple" in an ordinary dictionary, would you?

For example, If I compared character-by-character but also found how
different the lengths are, I could avoid a wrong logical answer as in
the example above.

Why is it a "wrong logical answer"?
Neither '1001' nor '999' are numbers but strings.
If you want to compare them like numbers you need to convert them to numbers first.

Bye, Andreas
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to