Default Constructor in Class in Python

Default constructor in Python programming is a constructor which has no parameters. The default constructor will be called at the time of creating object of that class.

Class Program using Default Constructor

Program

class cls: #'cls' is name of class.
    def __init__(self): #this is Default Constructor.
        print("This is Default Constructor")
    def fun(self): #this is function.
        print("This is Simple Function")
obj = cls() #'obj' is object of class 'cls', and calling default Constructor.
obj.fun()
Output
This is Default Constructor
This is Simple Function

Class Program using Default Constructor and Destructor

Program

class cls: #'cls' is name of class.
    def __init__(self): #this is Default Constructor.
        print("This is Default Constructor")
    def __del__(self): #this is Destructor.
        print("This is Destructor")
    def fun(self): #this is simple function.
        print("This is Simple Function")
obj = cls() #'obj' is object of class 'cls', and calling default constructor.
obj.fun() #calling 'fun()' function.
#when program Execution is finished then calling Destructor.
Output
This is Default Constructor
This is Simple Function
This is Destructor

Program Passing Argument to Constructor

Program

class mycls:
    def __init__(self, arg): #this is parameterized Constructor.
        print("This is "+ arg +" Constructor")
    def fun(self): #this is Simple function.
        print("This is Simple Function")
obj = mycls("Parameterized") #'obj' is object of class 'mycls' and calling
obj.fun()                    #and passing argument to parameter in Constructor.
Output
This is Parameterized Constructor
This is Simple Function

Program Passing Arguments to Constructor and Function
Program

class mycls: #'mycls' is name of Class.
    def __init__(self, name, roll, sec): #this is parameterized constructor.
        print("My Name is: ", name)
        print("My Roll No is: ", roll)
        print("My Section is: ", sec)
    def fun(self, arg): #this is parameterized function.
        print("This is "+ arg +" Function")
    def fun2(self): #this is simple function.
        print("This is Simple Function")
obj = mycls("HiLaLs Afridi", 12012, 'B') #calling and passing arguments,
obj.fun("Parameterized")                     #and 'ojb' is object.
obj.fun2()
Output
My Name is: HiLaLs Afridi
My Roll No is: 12012
My Section is: B
This is Parameterized Function
This is Simple Function