You may have encountered the methods in Python that are prefixed and suffixed with double underscores, those methods are called "Dunder Methods". These methods are also called "magic methods".
Dunder methods are used to overload specific methods in order to make their behaviour unique to that class.
Python has a rich collection of built-in dunder methods and a few are listed below:
__init__
__call__
__repr__
__str__
__len__
and more...
In this article, we will look at two dunder methods(__init__ and __call__) that are commonly used in Python classes. How do they differ, and when do we need to use them within the Python program?
This article was originally published on GeekPython and you can access it by clicking on the link below.
Top comments (0)