Python Basics
Python Advanced
Python Useful References
Python Useful Resources
Selected Reading
© 2011 TutorialsPoint.COM
|
Python Number cmp() Function
Description:
This function returns the sign of the difference of two numbers : -1 if x < y, 0 if x == y, or 1 if x > y
Syntax:
Parameters:
Here is the detail of parameters:
Return Value:
-1 if x < y, 0 if x == y, or 1 if x > y
Example:
#!/usr/bin/python
print "cmp(80, 100) : ", cmp(80, 100)
print "cmp(180, 100) : ", cmp(180, 100)
print "cmp(-80, 100) : ", cmp(-80, 100)
print "cmp(80, -100) : ", cmp(80, -100)
|
This will produce following result:
cmp(80, 100) : -1
cmp(180, 100) : 1
cmp(-80, 100) : -1
cmp(80, -100) : 1
|
|
|
|