I\'m wondering how Python does string comparison, more specifically how it determines the outcome when a less than (<
) or greater than (>
) op
Python and just about every other computer language use the same principles as (I hope) you would use when finding a word in a printed dictionary:
(1) Depending on the human language involved, you have a notion of character ordering: 'a' < 'b' < 'c' etc
(2) First character has more weight than second character: 'az' < 'za' (whether the language is written left-to-right or right-to-left or boustrophedon is quite irrelevant)
(3) If you run out of characters to test, the shorter string is less than the longer string: 'foo' < 'food'
Typically, in a computer language the "notion of character ordering" is rather primitive: each character has a human-language-independent number ord(character)
and characters are compared and sorted using that number. Often that ordering is not appropriate to the human language of the user, and then you need to get into "collating", a fun topic.