Python Interview Questions
How to overload constructors or methods in Python?
Python's constructor : _init__ () is the first method of a class. Whenever we try to instantiate an object __init__() is automatically invoked by python to initialize members of an object. We can't overload constructors or methods in Python. It shows an error if we try to overload.
class student:  
    def __init__(self,name):  = name  
    def __init__(self, name, email):  = name  = email  
# This line will generate an error  
#st = student("chanti")  
# This line will call the second constructor  
st = student("chanti", "")  
Output :