Between the characters and numbers in Python is how to compare the size?

Between the characters and numbers in Python is how to compare the size?

1. any two objects can be compared

2. The same type of objects (instances), if it is digital type (int/float/long/complex), in accordance with the simple size to compare; if is non numeric type and class (type) definition of the CMP (including GT, lt, etc.) in accordance with the CMP to compare, otherwise in accordance with the address (ID) to compare

3. Different types of objects (instances), if an object is one of the digital type (int/float/long/complex), digital object < other non numeric type object; if the two are non digital objects, in accordance with the order type name compared such as {} < "ABC" (in accordance with the "dict" < "STR"), and "ABC" > [1,2], "ABC" < (1,2).

4. for the custom class (type) example, if inherited from the basic types, according to the comparison of the basic types of rules (1-3). Otherwise, old-style class new-style class new-style class ", according to the type of name sequence comparison, old-style class were compared according to the address

5. bool type is a subclass of int, and True=1, False=0, 1-4 in comparison to compare, such as True > -1, True < 4.2, True < "ABC"

The above is for Python2.x, 3.x has great changes, such as STR and int will throw an exception.

Pingbacks are closed.

Comments are closed.