Where is the Python documentation for the special methods? (__init__, __new__, __len__, …)

前端 未结 9 1889
旧时难觅i
旧时难觅i 2020-12-08 02:00

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

相关标签:
9条回答
  • 2020-12-08 02:30

    Python's double underscore ("dunder") methods are also known as datamodel methods because they are at the core of Python's data model, providing a protocol for customizing (overloading) built-in methods. This is the reason why they are listed in the "Data Model" section of the Python's documentation.

    0 讨论(0)
  • 2020-12-08 02:34

    Here is a complete reference of all the Python magic methods.

    0 讨论(0)
  • 2020-12-08 02:41

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

    $ pydoc SPECIALMETHODS

    0 讨论(0)
  • 2020-12-08 02:43

    For somebody who is relatively new to Python, and for whom the documentation is often not quite accessible enough (like myself): somebody wrote a nice introduction with lots of examples on how the special (magic) methods work, how to use them, etc.

    0 讨论(0)
  • 2020-12-08 02:45

    Familiarize yourself with the dir function.

    0 讨论(0)
  • 2020-12-08 02:46

    Dive Into Python has an excellent appendix for them.

    0 讨论(0)
提交回复
热议问题