NOTE: The CMP () function has been removed from the Python3.
CMP (x, y)
Compares x with Y when x>y, returns 1 when X==y, returns 0 when X<y, returns 1;
1>>>CMP (1, 0)213>>>CMP ()4 05>>>CMP ()6-17>>>CMP ('a','b')8-19>>>CMP ('ABC','AB')Ten1 One #because ' ABC ' is longer than ' AB ', so determine ' abc ' > ' AB '
Special Places:
1. If the types of comparisons are different, but both are numbers (shaping and floating-point types), then it is necessary to make a forced number conversion (a bit of a question about which type to cast, but it does not matter);
2. If x is a number, Y is not a number, then X<y (the number is the smallest);
Print true = = 1trueprint true = = 0Falseprint false = = 1falseprint false = = 0True#Thetrue and false in the bool type are also represented by 1 and 0 in the computer
3. When x, y are not a number and the type is different, the name of its type (String,bool ...) to judge;
>>> CMP (True,'true')-1>>> cmp (False,'True ')-1
The above is a simple comparison of two data, the following is a comparison list.
>>> List1 = [a]>>> List2 = [a]>>>CMP (LIST1,LIST2) 0>>> list2[2] = 4>>>CMP (LIST1,LIST2)-1>>> List1 = ['ABC','a']>>> List2 = ['ABC', 1]>>>CMP (LIST1,LIST2)1>>> List2[1] ='b'>>>CMP (LIST1,LIST2)-1>>> List2[1] =True>>>CMP (LIST1,LIST2)1
Use of python-cmp ()