Skip to content Skip to sidebar Skip to footer

Where Is The Python Documentation For The Special Methods? (__init__, __new__, __len__, ...)

Where is a complete list of the special double-underscore/dunder methods that can be used in classes? (e.g., __init__, __new__, __len__, __add__)

Solution 1:

Please take a look at the special method names section in the Python language reference.

Solution 2:

If, like me, you want a plain, unadorned list, here it is. I compiled it based on the Python documentation link from the accepted answer.

__abs____add____and____call____class____cmp____coerce____complex____contains____del____delattr____delete____delitem____delslice____dict____div____divmod____eq____float____floordiv____ge____get____getattr____getattribute____getitem____getslice____gt____hash____hex____iadd____iand____idiv____ifloordiv____ilshift____imod____imul____index____init____instancecheck____int____invert____ior____ipow____irshift____isub____iter____itruediv____ixor____le____len____long____lshift____lt____metaclass____mod____mro____mul____ne____neg____new____nonzero____oct____or____pos____pow____radd____rand____rcmp____rdiv____rdivmod____repr____reversed____rfloordiv____rlshift____rmod____rmul____ror____rpow____rrshift____rshift____rsub____rtruediv____rxor____set____setattr____setitem____setslice____slots____str____sub____subclasscheck____truediv____unicode____weakref____xor__

Solution 3:

Dive Into Python has an excellent appendix for them.

Solution 4:

Solution 5:

Do this if you prefer reading documentation from a CLI instead of the browser.

$ pydoc SPECIALMETHODS

Post a Comment for "Where Is The Python Documentation For The Special Methods? (__init__, __new__, __len__, ...)"