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

26.3.2. Special methods for binary operators

Your class can define special methods with these names to tell Python how to handle binary operators such as “*” or “%”. In each case, the calling sequence will look something like this:

    def __method__(self, other):

The self argument is the left-hand operand, and the other argument is the right-hand operand. Your method will return the result of the operation.

For each operator, you may supply up to three methods: