Python super() FunctionPython Functions

Difficulty Level:
Difficulty Level:

The super() function returns a proxy object which allows you to refer the parent class using ‘super’.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

class A:
    def add(self, b):
        a = b + 2
        print(a)
class B(A):
    def add(self, n):
        super().add(n)
b = B()
b.add(4)

Output:

6

Syntax

super(type[, object-or-type])

Parameters

The function doesn’t take any parameters.

Return Value

It doesn’t return any values.

Advertisement

© 2021 Pythonexample.org, all rights reserved. Privacy Policy | Contact Us