Special methods

Special methods, or "dunder" methods (__init__, __repr__, __str__, __eq__, __len__), let a class integrate with the language's operations. Python calls them automatically, for example for print, == or len. They are not called directly in everyday code.

Example

def __repr__(self):
    return f'Point({self.x}, {self.y})'

Related concepts

The whole glossary