Next / Previous / Contents / TCC Help System / NM Tech homepage

26.3.1. Rich comparison methods

These special methods allow your class to specify what happens when comparison operators such as “<=” are used, and the left-hand operator is an instance of your class. (In most cases the right-hand operator is also an instance of the same class, but this is not actually required.)

In each case, the calling sequence for the method must look like this:

    def __method__(self, other):

The self argument is the left-hand operand and the other argument is the operand on the right hand of the operator.

Each method must return a numeric value:

OperatorMethod name