Skip to content

Latest commit

 

History

History
44 lines (31 loc) · 1.73 KB

README.md

File metadata and controls

44 lines (31 loc) · 1.73 KB

Magic Methods

Magic methods (formally known as special methods) are:

[...] called implicitly by Python to execute a certain operation on a type, such as addition. Such methods have names starting and ending with double underscores.

Glossary – Python 3 documentation

5 line example:

>>> class MyObj:
...     def __add__(self, other):
...         print(self, other)  # return something sensible
...
>>> MyObj() + 42
<__main__.MyObj object at 0x7f3637f8ea90> 42

Links


Licenses

  • Notebook: © Nick Timkovich, All rights reserved. Licensed under the MIT License.
  • Slide text, figures (excluding trademarks and logos), and source listings, excluding style elements © Nick Timkovich, All rights reserved. Licensed under CC-BY-SA 4.0
  • Typeset slides and styles: © Telnyx, LLC, All rights reserved. Licensed under CC-BY-NC-ND 4.0.
  • Duck cutout is a derivative of a photo by Bengt Nyman, and licensed under CC-BY-SA 4.0