Ads

Python 6 - __init__ vs __new__ in python

Hello Friends,

Welcome to Python article, I am Chakrapani Upadhyaya a full stack engineer.

In this article we will understand the usage of __init__ and __new__ methods.


__init__

I would like to say that, it is not a constructor, But it is a method called immediately after creation of object.

Technically speaking in python __new__ method acts like a constructor, constructor is a method which creates the object and __init__ is the initializer.

It does not return anything, it is only responsible for initializing the object after its been created.

__new__:

It is the first step of creation.

It is called first and responsible for returning a new instance of your class, it consists __init__

That's it for right now, See you in next article, until then take care bye.

Tags

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !