Sequence objects may be compared to other objects with the same sequence type. The comparison uses lexicographical ordering: first, the first two items are compared, and if they differ this determines the outcome of the comparison; if they are equal, the next two items are compared, and so on, until either sequence is exhausted. If two items to be compared are themselves sequences of the same type, the lexicographical comparison is carried out recursively. If all items of two sequences compare equal, the sequences are considered equal. If one sequence is an initial subsequence of the other, the shorter sequence is the smaller (lesser) one. Lexicographical ordering for strings uses the ASCII ordering for individual characters.
'aaa' < 'z' True 'aaa' < 'zzz' True 'aaa' < 'a' False 'A' < 'a' True
Note that comparing objects of different types is legal. The outcome is deterministic but arbitrary: the types are ordered by their name. Thus, a list is always smaller than a string, a string is always smaller than a tuple, etc.
When strings are compared their ordinal values are compared with the function ord( ).