- It is used to initialize the values of the instance attributes of the class
- In Python the concept of constructor overloading/ multiple constructors is not present but similar functionality can be implemented by using class methods
- The
cls()
method call the constructor of the class which will create a new instance of the class - The
__init__
method can not have a return value (It was cause an Error)
_new_ Attribute
- The
__new__
attribute is used to create a instance of a class - When we create a new instance of a class the
__new__
method is called first followed by__init__
where the instance attributes are initialized - It is very uncommon use case where we need to overwrite the default implementation of this method (It can be modified to implement Singleton concept)
Python: new magic method explained - Lintel Technologies Blog