0 votes
in Python by

What are the Dunder/Magic/Special methods in Python? Name a few.

1 Answer

0 votes
by

Dunder (derived from double underscore) methods are special/magic predefined methods in Python, with names that start and end with a double underscore. There's nothing really magical about them. Examples of these include:

  • init - constructor
  • str, repr - object representation (casting to string, printing)
  • len, next... - generators
  • enter, exit - context managers
  • eq, lt, gt - operator overloading
...