Constructor is a special type of method that is used to initialize the object.A constructor does not have any return type.
A constructor has a same name as the class in which it declare or use.Constructor can not be abstracted,static,final or synchronized.
class School: def __init__(self): print("Constructor Example") def show(self,name): print("Your School Name Is:",name) school = School() school.show("DAV")
output:Constructor Example
Your School Name Is:DAV
class School: def __init__(self, name): print("Constructor Example") self.name = name def show(self): print("Your Name Is :",self.name) school = School("Rahul") school.show()
output:Constructor Example
Your Name Is :Rahul