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( will look like
this:
x,
y)
def __divmod__(self, other):
...
In this method, the value of the first argument will be
passed to self and the second argument
to other.
| Function | Method |
|---|---|
abs | __abs__ |
complex | __complex__ |
divmod | __divmod__ |
hex | __hex__ |
int | __int__ |
len | __len__ |
long | __long__ |
mod | __mod__ |
oct | __oct__ |
str | __str__ |
unicode | __unicode__ |