Sequence objects can be compared to other objects of the same type. The comparison operation is performed in the words: first compare the first two elements, if the difference determines the result of the comparison; if the same, the two elements are compared, so that all sequences are completed. Comparison. If the two elements themselves are the same type of sequence, the recursive words are compared. If all children of the two sequences are equal, they will consider the sequence equal. If a sequence is the initial subsequence of another sequence, a shorter sequence is less than one. The character of the string is in order of the single-character ASCII order. Here are some examples of comparison between the same type of sequence:
Different types of objects are legal. The output result is determined rather than arbitrary: Types are sorted by their name. Thus, a linked list is always less than a string, a string is always less than one tuple, and the like. When the numerical type is compared, the data type is unified, so 0 is equal to 0.0, as follows
>>> (1, 2, 3) <(1, 2, 4) True >>> [1, 2, 3] <[1, 2, 4] true >>> 'ABC' <'C'true> >> (1, 2, 3, 4) <(1, 2, 4) True >>> (1, 2) <(1, 2, -1) True >>> (1, 2, 3) == (1.0, 2.0, 3.0) True >>> (1, 2, ('AA', 'A')) <(1, 2, ('ab', 'a')) True >>> [1, 2 ] <(1, 2) True >>>