class ConstructorExample1: x=0 y=0; def __init__(self): #0-arg constructor self.x=100 self.y=200 def show(self): print("x=",self.x) print("y=",self.y) ob=ConstructorExample1() #object declaration ob.show()
Output:
x= 100
y= 200
Example:
class ConstructorExample2: x=0 y=0 def __init__(self,p,q): #parameterized constructor self.x=p self.y=q def show(self): print("x=",self.x) print("y=",self.y) ob=ConstructorExample2(400,500) #object declaration ob.show()
Output:
x= 400
y= 500
Example:
class Example: def __init__(self): #constructor print("object created") def __del__(self): #destructor print("object destroyed") obj=Example() #object declaration del obj
Output:
object created
object destroyed
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc