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 from x[i]
__setitem__
: used when writing to x[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 by format()
function (and f-strings)
__hash__
: used by hash()
__bytes__
: used by bytes()
__bool__
: used by bool()
__iter__
: used by iter()
iterator.__next__()
:
__reversed__
:
__contains__
:
__dir__
: used by dir()
__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__
:
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__
__dict__
(but their instances might??).
slots
optionSee: