What
is constructor and its types ?
Ans.-Constructors are generally used for
instantiating an object. The task of constructor is to initialize to the data
member of the class when an object of class is created. In python the _init_()
method is called the constructor and is always called when an object is
created.
Syntax:-
Def_init_(self):
#Body of
constructor
Types of constructor:-
1.)Default constructors
2.) parameterized constructor
Default constructor:- The default constructor is simple constructor which does not
accept any arguments. It’s definition has only one argument which is a
reference to the instance being constructed.
Parameterized
constructor:-Constructor
with parameters is known as parameterized constructor. The parameterized
constructor take its first argument as a reference to the instance being constructed
known as self and the rest of the arguments are provided by the programmer.