Python Language / Python Super Function

It allows us to call a method of parent class.

Python Super Function
Program Output

class Parent:
 def __init__(self, txt):
  self.message = txt
def sendmessage(self):
 print(self.message)

class Child(Parent):
 def __init__(self, txt):
  super().__init__(txt)

obj1 = Child("child to parent Parameter passing")
obj1.sendmessage()

child to parent Parameter passing

class Parent:
 def function1(self):
  print("this is function 1")

class Child(Parent):
 def function2(self):
  super().function1()
 print("function2")

function2


Home     Back