Python 3 reference · Built-in Functions

Python super() Function

Return a proxy that calls methods of the parent class, so a subclass can extend a method instead of replacing it.

Python 3 Since 3.0

Syntax

super()
super(type, object_or_type)

Parameters

ParameterDescription
type, object_or_type optional Rarely needed: the explicit two-argument form.

Return value

A proxy object that forwards method calls to the next class in the MRO.

Examples

Call the parent constructorTry it yourself
class Animal:
    def __init__(self, name):
        self.name = name

class Dog(Animal):
    def __init__(self, name, breed):
        super().__init__(name)   # run the parent's __init__
        self.breed = breed

d = Dog("Rex", "collie")
print(d.name, d.breed)

Output

Rex collie
Extend a parent methodTry it yourself
class Logger:
    def log(self, msg):
        print("LOG:", msg)

class TimestampLogger(Logger):
    def log(self, msg):
        super().log(f"[12:00] {msg}")

TimestampLogger().log("started")

Output

LOG: [12:00] started

Good to know

With multiple inheritance, super() follows the method resolution order (Class.__mro__), not just the direct parent, so every class in the chain should call super() for cooperative methods.

Version history

VersionChange
Python 3.0Added