https://docs.python.org/3/reference/datamodel.html
__init__: constructor__del__: destructor ?? (use with care)__delete__:__new__: this is called before__init____get__: read attribute value__set__: write attribute value__getattr__:__getattribute__:__setattr__:__delattr__:__getitem__: used when reading fromx[i]__setitem__: used when writing tox[i]__delitem__: used when deleting__missing__:__repr__: representation of object as a string__str__: human readable representation of object as string__lt__, -__gt__, -__le__, -__ge__, -__eq__, -__ne__: comparison__format__: used byformat()function (and f-strings)__hash__: used byhash()__bytes__: used bybytes()__bool__: used bybool()__iter__: used byiter()iterator.__next__():__reversed__:__contains__:__dir__: used bydir()__call__:__len__:__length_hint__:__enter__: enter context manager__exit__: leave context manager__objclass__:__slots__:__init_subclass__:__set_name__:__prepare__:__mro_entries__:__classcell__: CPython specific__class__:__instancecheck__:__subclasscheck__:__class_getitem__:__match_args__:__complex__:__int__:__float__:__index__:__round__:__trunc__:__floor__:__ceil__:__buffer__:__release_buffer__:__await__:__aiter__:__anext__:
Arithmetic and related
| Function | Function (rev) | Notation |
|---|---|---|
__add__ |
__radd__ |
+ |
__sub__ |
__rsub__ |
- |
__mul__ |
__rmul__ |
* |
__matmul__ |
__rmatmul__ |
@ |
__truediv__ |
__rtruediv__ |
/ |
__floordiv__ |
__rfloordiv__ |
// |
__mod__ |
__rmod__ |
% |
__divmod__ |
__rdivmod__ |
divmod() |
__pow__ |
__rpow__ |
** |
__lshift__ |
__rlshift__ |
<< |
__rshift__ |
__rrshift__ |
>> |
__and__ |
__rand__ |
& |
__xor__ |
__rxor__ |
^ |
__or__ |
__ror__ |
│ |
Functions with the r prefix are the same except that the order of arguments is reversed.
Note: Ternary pow() will not try calling rpow().
—
| Function | Notation |
|---|---|
__iadd__ |
+= |
__isub__ |
-= |
__imul__ |
*= |
__imatmul__ |
@= |
__itruediv__ |
/= |
__ifloordiv__ |
//= |
__imod__ |
%= |
__ipow__ |
**= |
__ilshift__ |
<<= |
__irshift__ |
>>= |
__iand__ |
&= |
__ixor__ |
^= |
__ior__ |
│= |
(divmod isn't there in this list.)
—
| Function | Notation |
|---|---|
__neg__ |
- |
__pos__ |
+ |
__invert__ |
~ |
__slot__
- Classes with slots does not have
__dict__(but their instances might??).- Saves space.
- Faster attribute access
- Remark: dataclass has a
slotsoption
See: