In the update for Python 3, str and int are no longer supported for direct determination
' Ten '>>> a > 9Traceback (most recent call last): File "<pyshell#18>", line 1, in <module > a > 9TypeError: ' > ' not supported between instances of ' str ' and ' int '
In Python 2
' 1 '>>> a >true>>> a > 100000true
Description in the manual
... the choice whether one object is considered smaller or larger than another one was made arbitrarily but consistently
- 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 numeric object < Other non-numeric objects, if two are non-numeric objects, then the order of the type name is compared, such as {} < ABC "(By" dict "<" str "), and" abc "> [+]," 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.
That is, the numeric object in Python 2 < Other non-numeric objects, the string > number expression always returns True
So it does look 3 more rigorous, avoid some of the problems that may arise
[Python Basics] The difference between Python 2 and Python 3--operations between different data types