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

26.3.4. Special methods to emulate built-in functions

You can define special methods that will handle calls to some of Python's built-in functions. The number of arguments will be the same as for the built-in functions, except that self is always the first argument.

For example, a special method to handle calls to function divmod(x, y) will look like this:

    def __divmod__(self, other):
        ...

In this method, the value of the first argument will be passed to self and the second argument to other.

FunctionMethod
abs__abs__
complex__complex__
divmod__divmod__
hex__hex__
int__int__
len__len__
long__long__
mod__mod__
oct__oct__
str__str__
unicode__unicode__