Skip to content

nicktimko/talks-magicmethods

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published