The purpose of this special method is to implement comparison operations between instances. It will be called in these situations:
If the built-in cmp() function is
called to compare an instance of a class to some
other value, and the class has a .__cmp__() method, that method is called
to perform the comparison.
When an instance appears on the left-hand side of a
comparison (relational) operator, and that
instance's class has a the corresponding
rich-comparison method (such as .__eq__() for the “==” operator; see Section 26.3.1, “Rich comparison methods”), the
rich-comparison method will be called to perform
the comparison. and, if so, that method is called.
The comparison operators are “<”, “<=”,
“==”, “!=”, “>”, and “>=”.
However, if the class does not have the correct
rich-comparison method, but it does have a .__cmp__() method, that method will be
called to evaluate the comparison.
The calling sequence is:
def __cmp__(self, other):
...
The convention for return values is the same one
described in Section 20.8, “cmp(): Compare two values”: negative
if self precedes other,
positive if other precedes self, zero if they are considered equal.