Constructors purpose is to initialize a newly created object in any object oriented language like python. It is a part of the class in python. They are automatically invoked upon creation of a new object.
In python constructors are created using “__init__” method.
There are two types of constructors in python:-
- Default constructors- This constructor has only one argument and does not accept any other argument.
- Parameterized constructor- Constructors which has parameters are known as parameterized constructor.
syntax of a constructor:-
def __init__(self): #constructor's body
This is all about constructors in python.