Home >Backend Development >Python Tutorial >python function - cmp(x,y)

python function - cmp(x,y)

高洛峰
高洛峰Original
2016-10-17 14:57:101508browse

Today I will share a very useful and very simple function cmp in Python. You may have guessed it from the spelling. This is a comparison function. Well, yes, it has only three return values, positive number, 0, and negative number. Let’s take a look:

cmp(x, y)

Chinese description: Compare two objects x and y, if x y, return a positive number.

Version: This function is only available in python2 and is available in all versions of python2. However, this function has been deleted in python3, so special attention should be paid to this.


English description: Compare the two objects x and y and return an integer according to the outcome.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn