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

26.3. Special method names

Within a class, a number of reserved method names have special meaning. Here is a list of the ones covered in this document.

__abs__ Section 26.3.4, “Special methods to emulate built-in functions”
__add__ Section 26.3.2, “Special methods for binary operators”
__and__ Section 26.3.2, “Special methods for binary operators”
__call__ Section 26.3.5, “__call__(): What to do when someone calls an instance”
__cmp__ Section 26.3.6, “__cmp__(): Generalized comparison”
__complex__ Section 26.3.4, “Special methods to emulate built-in functions”
__contains__ Section 26.3.7, “__contains__(): The “in” and “not in” operators”
__del__ Section 26.3.8, “__del__(): Destructor”
__delattr__ Section 26.3.9, “__delattr__(): Delete an attribute”
__delitem__ Section 26.3.10, “__delitem__(): Delete one item of a sequence”
__divmod__ Section 26.3.4, “Special methods to emulate built-in functions”
__div__ Section 26.3.2, “Special methods for binary operators”
__divmod__ Section 26.3.4, “Special methods to emulate built-in functions”
__enter__ Section 26.3.11, “__enter__: Context manager initialization”
__exit__ Section 26.3.12, “__exit__: Context manager cleanup”
__eq__ Section 26.3.1, “Rich comparison methods”
__floordiv__ Section 26.3.2, “Special methods for binary operators”
__float__ Section 26.3.4, “Special methods to emulate built-in functions”
__ge__ Section 26.3.1, “Rich comparison methods”
__getattr__ Section 26.3.14, “__getattr__(): Handle a reference to an unknown attribute”
__getattribute__ Section 26.3.15, “__getattribute__(): Intercept all attribute references”
__getitem__ Section 26.3.16, “__getitem__(): Get one item from a sequence or mapping”
__gt__ Section 26.3.1, “Rich comparison methods”
__hex__ Section 26.3.4, “Special methods to emulate built-in functions”
__iadd__ Section 26.3.2, “Special methods for binary operators”
__iand__ Section 26.3.2, “Special methods for binary operators”
__idiv__ Section 26.3.2, “Special methods for binary operators”
__ifloordiv__ Section 26.3.2, “Special methods for binary operators”
__ilshift__ Section 26.3.2, “Special methods for binary operators”
__imod__ Section 26.3.2, “Special methods for binary operators”
__imul__ Section 26.3.2, “Special methods for binary operators”
__init__ Section 26, “Classes: Defining your own types”
__int__ Section 26.3.4, “Special methods to emulate built-in functions”
__invert__ Section 26.3.3, “Unary operator special methods”
__ior__ Section 26.3.2, “Special methods for binary operators”
__ipow__ Section 26.3.2, “Special methods for binary operators”
__irshift__ Section 26.3.2, “Special methods for binary operators”
__isub__ Section 26.3.2, “Special methods for binary operators”
__iter__ Section 26.3.17, “__iter__(): Create an iterator”
__ixor__ Section 26.3.2, “Special methods for binary operators”
__le__ Section 26.3.1, “Rich comparison methods”
__len__ Section 26.3.4, “Special methods to emulate built-in functions”
__long__ Section 26.3.4, “Special methods to emulate built-in functions”
__lshift__ Section 26.3.2, “Special methods for binary operators”
__lt__ Section 26.3.1, “Rich comparison methods”
__mod__ Section 26.3.2, “Special methods for binary operators”
__mul__ Section 26.3.2, “Special methods for binary operators”
__ne__ Section 26.3.1, “Rich comparison methods”
__neg__ Section 26.3.3, “Unary operator special methods”
__new__ Section 26.2.1, “__new__(): New instance creation”
__nonzero__ Section 26.3.18, “__nonzero__(): True/false evaluation”
__oct__ Section 26.3.4, “Special methods to emulate built-in functions”
__or__ Section 26.3.2, “Special methods for binary operators”
__pos__ Section 26.3.3, “Unary operator special methods”
__pow__ Section 26.3.2, “Special methods for binary operators”
__radd__ Section 26.3.2, “Special methods for binary operators”
__rand__ Section 26.3.2, “Special methods for binary operators”
__rdiv__ Section 26.3.2, “Special methods for binary operators”
__repr__ Section 26.3.19, “__repr__(): String representation”
__reversed__ Section 26.3.20, “__reversed__(): Implement the reversed() function”
__rfloordiv__ Section 26.3.2, “Special methods for binary operators”
__rlshift__ Section 26.3.2, “Special methods for binary operators”
__rmod__ Section 26.3.2, “Special methods for binary operators”
__rmul__ Section 26.3.2, “Special methods for binary operators”
__ror__ Section 26.3.2, “Special methods for binary operators”
__rpow__ Section 26.3.2, “Special methods for binary operators”
__rrshift__ Section 26.3.2, “Special methods for binary operators”
__rshift__ Section 26.3.2, “Special methods for binary operators”
__rsub__ Section 26.3.2, “Special methods for binary operators”
__rxor__ Section 26.3.2, “Special methods for binary operators”
__setattr__ Section 26.3.21, “__setattr__(): Intercept all attribute changes”
__setitem__ Section 26.3.22, “__setitem__(): Assign a value to one item of a sequence”
__str__ Section 26.3.4, “Special methods to emulate built-in functions”
__sub__ Section 26.3.2, “Special methods for binary operators”
__unicode__ Section 26.3.4, “Special methods to emulate built-in functions”
__xor__ Section 26.3.2, “Special methods for binary operators”

The most important special method name is the class constructor, .__init__().

Many special methods fall into broad categories: