A brief introduction to the use of the CMP () method in the python2.x version

Source: Internet
Author: User
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
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.