In Python basic programming, there's an advanced sort of:"If you want elements to be sorted in a particular way, rather than the sort function by default, in ascending order of elements according to Python's default collation, which is explained in
In this article, let's look at the built-in functions in the Python dictionary, which I'll
What are the CMP in PythonFor instructions, and
pythoncmp ()method to parse. Well, don't say much, let's get into the article.
Describe
The CMP () function
Analysis of the cmp comparison principle of Python built-in comparison functions
Cmp (x, y): compares two objects. if the former is smaller than the latter,-1 is returned. if the former is equal, 0 is returned. if the former is greater than the
This article mainly introduces the python2.x version of the CMP () method of using the tutorial, in the python3.x version of the method is no longer built in, the need for friends can refer to the
The CMP () method returns a symbol of the
Comparison principle of CMP comparison function in Python
CMP (x, y): Compares 2 objects, which are less than the latter return-1, and equal returns 0, greater than the latter returning 1.
Comparison principle of CMP comparison function in Python
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 X1>>>CMP (1, 0)213>>>CMP ()4 05>>>CMP ()6-17>>>CMP ('a','b')8-19>>>CMP
CMP (x, y): Compares 2 objects, which are less than the latter return-1, and equal returns 0, greater than the latter returning 1.
Comparison principle of CMP comparison function in Python
The CMP functions of Python can be compared between the same
DescribeThe CMP (x, y) function is used to compare 2 objects if x y returns 1.GrammarThe following is the syntax for the CMP () method:CMP (x, y)ParametersX--Numeric expression.Y--numeric expression.return valueIf x y returns 1.InstanceThe
Python development [Notes]: sort Sorting Algorithm (cmp, key, reverse), pythoncmpSort
The sorting function is often used in the program. Python provides the sort and sorted functions, one in-situ sorting and one Returning New results after sorting.
1
Python function-cmp (x, y) today I will share a very useful and simple function named cmp in python. as you may have guessed in spelling, this is a comparison function, yes, it only returns three values, positive, 0, and negative. let's take a look:
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.