Post

Python super()

The super() is a built-in python function that gives access to methods and properties of a parent or sibling class object.

Python super()

The syntax of super() function is:

1
2
super()

super() Parameters

The super() function does not take any parameters.

Example 1: How to use super() functions in python?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Parent:
  def __init__(self, txt):
    self.message = txt

  def printmessage(self):
    print(self.message)

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

x = Child("Hello, and welcome!")

x.printmessage()

Output:

1
2
Hello, and welcome!

This post is licensed under CC BY 4.0 by the author.