Python super() function

Instance

Create a class that inherits all methods and properties from another class:

class Parent:
  def __init__(self, txt):
    self.message
  def printmessage(self):
    print(self.message)
class Child(Parent):
  def __init__(self, txt):
    super().__init__(txt)
x = Child("Hello, and welcome!")
x.printmessage()

Running Instance

Definition and Usage

The super() function is used to provide access to methods and properties of the parent class or sibling class.

The super() function returns an object representing the parent class.

Syntax

super()

Parameter Value

No Parameters