dunder method

A method whose name starts and ends with two underscores, such as __init__ or __len__, which Python calls for you to implement built-in behaviour.

In more detail

Dunder is short for double underscore. len(x) calls x.__len__(), a + b calls a.__add__(b) and == calls __eq__, so defining dunder methods lets your own classes work with Python's operators and built-ins. You rarely call them directly.

Related terms

Taught in

References

Certification courses