Reply content:
@ Yan Hang's answer is not right.
Reference 5. Built-in the
instructions in Types, the CPython is compared according to the following rules (own summary):
- Any two objects can be compared
- Objects of the same type (instances), if they are numeric (Int/float/long/complex), are compared by simple size, if they are non-numeric, and __cmp__ (including __gt__,__lt__, etc.) are defined in the class (type), compared by __cmp__. Otherwise, by address (ID) to compare
- Different types of objects (instances), if one of the comparison objects is a numeric type (Int/float/long/complex, etc.), then the <其它非数字型的对象;如果两个都是非数字型的对象,则按照类型名的顺序比较,如{}> < "abc"(按照"dict"="" "str"),而"abc"=""> object of the number type [up], "ABC" < (.)
- For a custom class (type) instance, if it inherits from the base type, it is compared by the rule of the base type (1-3). Otherwise, Old-style class < New-style class, New-style class is compared by type name order, and Old-style class is compared by address
- The bool type is a subclass of int, and true=1, false=0, compare by 1-4, such as true >-1, True < 4.2, true < "abc", etc.
The above answer is a big change for python2.x,3.x, such as when str and int compare, throw an exception.
Back to the topic, the comparison of characters and numbers conforms to rule 3, so the numbers<>
100< ' a '