
Operator Overloading Methods
|
63
__delitem__(self, key)
Invoked on del self[key]. This method is for index/key
component deletion.
As of Python 2.0, the following three methods are consid-
ered deprecated, but are still supported. They are called only
when a simple two-item slice with a single colon is used and
the slice method is defined. For slice operations involving
extended three-item slice notation, or in the absence of the
slice method,
__getitem__, __setitem__,or__delitem__ is
called instead, with a slice object as its argument.
__getslice__(self, low, high)
Invoked on self[low:high] for sequence slicing. This
format is considered deprecated as of Python 2.0.
If no
__getslice_ _
is found, or if an extended three-item slice
is used, then a slice object is created and is passed to the
__getitem_ _
method.
__setslice__(self, low, high, seq)
Invoked on self[low:high]=seq for sequence slice assign-
ment.
__delslice__(self, low, high)
Invoked on del self[low:high] for sequence slice dele-
tion.
For Numbers (Binary Operators)
Basic binary methods
__add__(self, other)
Invoked on self + other for numeric addition, or
sequence concatenation.
__sub__(self, other)
Invoked on self - other.
__mul__(self, other)
Invoked on self * other for numeric multiplication, or
sequence repetition.