Next / Previous / Contents / Shipman's homepage

20.8. cmp(): Compare two values

This function compares the values of two arguments x and y:

cmp(x, y)

The return value is:

The built-in cmp() function will typically return only the values -1, 0, or 1. However, there are other places that expect functions with the same calling sequence, and those functions may return other values. It is best to observe only the sign of the result.

>>> cmp(2,5)
>>> cmp(5,5)
>>> cmp(5,2)
>>> cmp('aardvark', 'aardwolf')