The CMP () method compares the elements of a two list.
Grammar
The following is the syntax for the CMP () method:
CMP (List1, List2)
Parameters
- List1--This is the first list to be compared
- List2--This is the second list to be compared
return value
If the element is of the same type, the comparison is performed and the result is returned. If the elements are different types, check to see if they are numbers
- Force a numeric comparison if it is a number if necessary
- If either element is a number and then the other element is "large" (the number is "minimum")
- Otherwise, types are sorted alphabetically by name
If the end of one of the lists is reached, the longer list is "large". If the list is exhausted and the same data is shared, the result is tied, which means that 0 is returned
Example
The following example shows the use of the CMP () method.
#!/usr/bin/pythonlist1, List2 = [123, ' XYZ '], [456, ' ABC ']print CMP (List1, List2);p rint cmp (LIST2, list1); list3 = List2 + [786];p rint cmp (LIST2, LIST3)
When we run the above program, it produces the following results:
-11-1