Python Info
Share
Explore

icon picker
Python Dunders

A compilaton of all Python dunder definitions with some key attributes

Category
Start
End
Writable
Called
Returns
Package
Search
Name
Category
Start
End
Writable
Called
Returns
Usage
Package
URL
1
__ilshift__
Binary
Yes
Yes
Yes
x <<= y
2
__invert__
Binary
Yes
Yes
Yes
~x
3
__irshift__
Binary
Yes
Yes
Yes
x >>= y
4
__ixor__
Binary
Yes
Yes
Yes
x ^= y
5
__lshift__
Binary
Yes
Yes
Yes
x << y
6
__rlshift__
Binary
Yes
Yes
Yes
y << x
7
__rrshift__
Binary
Yes
Yes
Yes
y >> x
8
__rshift__
Binary
Yes
Yes
Yes
x >> y
9
__annotations__
Callable
Yes
No
A dict containing annotations of parameters. The keys of the dict are the parameter names, and 'return' for the return annotation, if provided. For more information on working with this attribute, see Annotations Best Practices.
10
__call__
Callable
Yes
Yes
Yes
x()
11
__closure__
Callable
No
No
None or a tuple of cells that contain bindings for the function’s free variables. See below for information on the cell_contents attribute.
12
__code__
Callable
Yes
No
The code object representing the compiled function body.
13
__defaults__
Callable
Yes
No
A tuple containing default argument values for those arguments that have defaults, or None if no arguments have a default value.
14
__globals__
Callable
No
No
A reference to the dictionary that holds the function’s global variables — the global namespace of the module in which the function was defined.
15
__kwdefaults__
Callable
Yes
No
A dict containing defaults for keyword-only parameters.
16
__bool__
Cast
Yes
Yes
Yes
bool(x)
17
__bytes__
Cast
Yes
Yes
Yes
bytes(x)
18
__complex__
Cast
Yes
Yes
Yes
complex(x)
19
__float__
Cast
Yes
Yes
Yes
float(x)
20
__hash__
Cast
Yes
Yes
hash(x)
21
__int__
Cast
Yes
Yes
Yes
int(x)
22
__iter__
Cast
Yes
Yes
Yes
iter(x)
23
__nonzero__
Cast
2
Like __bool__
24
__cmp__
Compare
2
Yes
Yes
Yes
25
__eq__
Compare
Yes
Yes
x == y
26
__ge__
Compare
Yes
Yes
x >= y
27
__gt__
Compare
Yes
Yes
x > y
28
__instancecheck__
Compare
Yes
Yes
Yes
isinstance(y, x) Defined for x's metaclass
29
__le__
Compare
Yes
Yes
Yes
x <= y
30
__lt__
Compare
Yes
Yes
Yes
x < y
31
__ne__
Compare
Yes
Yes
x != y
32
__subclasscheck__
Compare
Yes
Yes
Yes
issubclass(y, x)
33
__subclasshook__
Compare
Yes
Yes
Yes
issubclass(y, x), called for x if x is derived from ABC
abc
34
__enter__
Context
Yes
Yes
Yes
with x:
35
__exit__
Context
Yes
Yes
Yes
with x:
36
__del__
Delete
Yes
Yes
__del__ is a finalizer. It is called when an object is garbage collected which happens at some point after all references to the object have been deleted.
37
__delattr__
Delete
Yes
Yes
Called for A when calling del A.x
38
__delitem__
Delete
Yes
Yes
Called for A when calling del A[n] or A[n:n] in which case a slice object is given as key
39
__delslice__
Delete
2
Yes
Yes
40
__delete__
Descriptor
No
Yes
del X.y will call y's __delete__ (property)
41
__get__
Descriptor
No
Yes
Yes
X.y = Y(), X.y will call y's __get__ (property)
42
__set__
Descriptor
Yes
Yes
No
X.y = Y(), X.y = z will call y's __set__ (property)
43
__all__
Info
Yes
No
module.__all__, decides what's exported by module
44
__bases__
Info
Yes
No
Returns a list of classes that X has directly inherited from
45
__class__
Info
No
No
type(x)[y]
46
__dict__
Info
Yes
No
The namespace supporting arbitrary function attributes.
47
__doc__
Info
Yes
No
The function’s documentation string, or None if unavailable; not inherited by subclasses.
48
__module__
Info
Yes
No
The name of the module the function was defined in, or None if unavailable.
49
__name__
Info
Yes
No
The function’s name.
50
__qualname__
Info
3.3
Yes
No
The function’s qualified name.
51
__sizeof__
Info
Yes
Yes
Yes
sys.getsizeof(x), Internal size in bytes
52
__slots__
Info
Yes / No
No
53
__subclasses__
Info
Yes
Yes
Yes
Returns a list of classes that directly inherited X
54
__contains__
Iterable
Yes
Yes
Yes
x in y
55
__getitem__
Iterable
Yes
Yes
A[n]
56
__getslice__
Iterable
2
Yes
Yes
57
__index__
Iterable
Yes
Yes
Yes
list[x] calls x.__index__
58
__len__
Iterable
Yes
Yes
Yes
len(x), also called by bool(x), guessing it's cause empty iterables should return False
59
__length_hint__
Iterable
Yes
Yes
Yes
Estimate of len if len(x) raises TypeError, defined in iterators
60
__missing__
Iterable
2.5
Yes
Yes
No
class X(dict) X()["missing"] Only works for subclass of dict, called if key is missing
61
__next__
Iterable
Yes
Yes
Yes
next(x)
62
__reversed__
Iterable
Yes
Yes
Yes
reversed(x), if not defined then len and getitem will be used
63
__setitem__
Iterable
Yes
Yes
A[n] = x
64
__setslice__
Iterable
2
Yes
Yes
65
__and__
Logic
Yes
Yes
Yes
x & y
66
__iand__
Logic
Yes
Yes
Yes
x &= y
67
__ior__
Logic
Yes
Yes
Yes
x |= y
68
__or__
Logic
Yes
Yes
Yes
x | y
69
__rand__
Logic
Yes
Yes
Yes
y & x, used if y hasn't implemented it or if that returns NotImplementedError
70
__ror__
Logic
Yes
Yes
Yes
y | x, used if y hasn't implemented it or if that returns NotImplementedError
71
__rxor__
Logic
Yes
Yes
Yes
y ^ x, used if y hasn't implemented it or if that returns NotImplementedError
72
__xor__
Logic
x ^ y
73
__class_getitem__
Lookup
3.7
Yes
Yes
Yes
X[n]
74
__dir__
Lookup
Yes
Yes
Yes
dir(x)
75
__getattr__
Lookup
Yes
Yes
Called for attrs that aren't already defined.
76
__getattribute__
Lookup
Yes
Yes
Called unconditionally to implement attribute accesses for instances of the class.
77
__setattr__
Lookup
Yes
Yes
A.y = x
78
__abs__
Math
Yes
Yes
Yes
abs(x)
79
__add__
Math
Yes
Yes
Yes
x + y
80
__ceil__
Math
Yes
Yes
Yes
math.ceil(x)
81
__divmod__
Math
Yes
Yes
Yes
divmod(x, y) -> (i, j)
82
__floor__
Math
Yes
Yes
Yes
math.floor(x)
83
__floordiv__
Math
Yes
Yes
Yes
x // y
84
__iadd__
Math
Yes
Yes
Yes
x += y
85
__ifloordiv__
Math
Yes
Yes
Yes
x //= y
86
__imod__
Math
Yes
Yes
Yes
x %= y
87
__imul__
Math
Yes
Yes
Yes
x *= y
88
__ipow__
Math
Yes
Yes
Yes
x **= y
89
__isub__
Math
Yes
Yes
Yes
x -= y
90
__itruediv__
Math
Yes
Yes
Yes
x /= y
91
__mod__
Math
Yes
Yes
Yes
x % y
92
__mul__
Math
Yes
Yes
Yes
x * y
93
__neg__
Math
Yes
Yes
Yes
-x
94
__pos__
Math
Yes
Yes
Yes
+x
95
__pow__
Math
Yes
Yes
Yes
pow(x, y)
96
__radd__
Math
Yes
Yes
Yes
y + x, used if y hasn't implemented it or if that returns NotImplementedError
97
__rdiv__
Math
Yes
Yes
Yes
y / x, used if y hasn't implemented it or if that returns NotImplementedError
98
__rdivmod__
Math
Yes
Yes
Yes
divmod(y, x), used if y hasn't implemented it or if that returns NotImplementedError
99
__rfloordiv__
Math
Yes
Yes
Yes
y // x, used if y hasn't implemented it or if that returns NotImplementedError
100
__rmod__
Math
Yes
Yes
Yes
y % x, used if y hasn't implemented it or if that returns NotImplementedError
101
__rmul__
Math
Yes
Yes
Yes
y * x, used if y hasn't implemented it or if that returns NotImplementedError
102
__round__
Math
Yes
Yes
Yes
round(x)
103
__rpow__
Math
Yes
Yes
Yes
pow(y, x), used if y hasn't implemented it or if that returns NotImplementedError
104
__rsub__
Math
Yes
Yes
Yes
y - x, used if y hasn't implemented it or if that returns NotImplementedError
105
__rtruediv__
Math
Yes
Yes
Yes
y / x, used if y hasn't implemented it or if that returns NotImplementedError
106
__sub__
Math
Yes
Yes
Yes
x - y
107
__truediv__
Math
Yes
Yes
Yes
x / y
108
__trunc__
Math
Yes
Yes
Yes
math.trunc(x), floors positive, ceils negative
109
__imatmul__
Matrix
Yes
Yes
Yes
x @= y
110
__matmul__
Matrix
3.5
Yes
Yes
Yes
x @ y
111
__rmatmul__
Matrix
Yes
Yes
Yes
y @ x, used if y hasn't implemented it or if that returns NotImplementedError
112
__init__
Object
Yes
Yes
No
cls()
113
__init_subclass__
Object
Yes
Yes
No
class Y(X): called for X if something inherits it
114
__new__
Object
Yes
Yes
No
Called before init to create object of class without parameters
115
__prepare__
Object
3.0
Yes
Yes
Yes
Return namespace for metaclass
116
__set_name__
Object
3.6
Yes
Yes
No
class Y: foo = X() Called for X, attr has to be defined within class scope
117
__getnewargs__
Pickle
Yes
Yes
Yes
return a tuple of how to call __new__ with pickle.loads(str), positional only
118
__getnewargs_ex__
Pickle
Yes
Yes
Yes
Like __getnewargs__ but key-word only
119
__getstate__
Pickle
Yes
Yes
Yes
__dict__ is pickled if this isn't defined, otherwise return obj is pickled
120
__reduce__
Pickle
Yes
Yes
Yes
Low level interface for pickling, alternative to __getstate__ and __setstate__. Takes no parameters
121
__reduce_ex__
Pickle
Yes
Yes
Yes
Takes presedence over __reduce__, takes one integer as parameter (the protocol number)
122
__setstate__
Pickle
Yes
Yes
Yes
Returns new __dict__ for unpickled obj
123
__format__
String
2.7
Yes
Yes
Yes
"{0}".format(4) or format(X)
124
__fspath__
String
3.6
Yes
Yes
Yes
os.fspath(x)
125
__repr__
String
Yes
Yes
Yes
repr(x)
126
__str__
String
Yes
Yes
Yes
str(x)
127
__aenter__
Thread
Yes
Yes
Yes
async with X():
128
__aexit__
Thread
Yes
Yes
Yes
async with X():
129
__aiter__
Thread
130
__anext__
Thread
131
__await__
Thread
Yes
Yes
Yes
Used by asyncio, usually not needed
There are no rows in this table

Share
 
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.