Copyright © tutorialspoint.com

Python Number cmp() Function

previous next


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:

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

Copyright © tutorialspoint.com