I\'m wondering how Python does string comparison, more specifically how it determines the outcome when a less than (<
) or greater than (>
) op
Python string comparison is lexicographic:
From Python Docs: http://docs.python.org/reference/expressions.html
Strings are compared lexicographically using the numeric equivalents (the result of the built-in function ord()) of their characters. Unicode and 8-bit strings are fully interoperable in this behavior.
Hence in your example, 'abc' < 'bac'
, 'a' comes before (less-than) 'b' numerically (in ASCII and Unicode representations), so the comparison ends right there.