June 2002
Beginner to intermediate
640 pages
14h 24m
English
This section deals mostly with functions that are longhand for operators.
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 ...
Read now
Unlock full access