__init__ and __call__ in Python - How they differ and what do they do?

sachingeek

Sachin

Posted on March 7, 2023

__init__ and __call__ in Python - How they differ and what do they do?

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.

__init__ and __call__ In Python - What Do They Do?

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 o...

favicon geekpython.in
💖 💪 🙅 🚩
sachingeek
Sachin

Posted on March 7, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related