cmp() method in Python 2.x compares two integers and returns -1, 0, 1 according to comparison.
cmp() does not work in python 3.x. You might want to see list comparison in Python.
Syntax: cmp(a, b) Parameters: a and b are the two numbers in which the comparison is being done. Returns: -1 if a<b 0 if a=b 1 if a>b
-1 0 1
Practical Application: Program to check if a number is even or odd using cmp function.
Approach: Compare 0 and n%2, if it returns 0, then it is even, else its odd.
Below is the Python implementation of the above program:
- Wand function() function in Python
- Python - Call function from another function
- ord() function in Python
- Help function in Python
- Python str() function
- Python | How to get function name ?
- sum() function in Python
- Python map() function
- Python | oct() function
- Python | dir() function
- Python | now() function
- Python | hex() function
- Python | int() function
- id() function in Python
- Python tell() function
- turtle.dot() function in Python
- Python - Get Function Signature
- round() function in Python
- Python | frexp() Function
- vars() function in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.