Operations
This section deals mostly with functions that are longhand for operators.
Numeric Operations: cmp(), divmod(), pow(), abs(), round()
cmp(x,y) compares two numeric types. It also works for sequences, dictionaries, and other numeric objects. cmp() returns a positive number if the x argument is greater than the y argument, a negative number if the y argument is greater than the x argument, and 0 if x and y are equal.
>>> cmp(1,0) 1 >>> cmp(0,1) -1 >>> cmp(0,0) 0
cmp() is related to the equality operators (==, >=, <=, etc.). If you want these operators to work with class instances, you need to implement cmp() for the class by executing cmp(instance1, instance2), instance1 == instance2, or instance1 > instance2).
The divmod() function ...
Get Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.