Tutorials Point


  Python Basics
  Python Advanced
  Python Useful References
  Python Useful Resources
  Selected Reading

© 2011 TutorialsPoint.COM


  Home     References     Discussion Forums     About TP  

Python Number cmp() Function


previous next AddThis Social Bookmark Button


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:

cmp( x, y )

Parameters:

Here is the detail of parameters:

  • x: This is a numeric expression.

  • y: This is also a numeric expression.

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


previous next Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names