The primary purpose of
super() in Python is to call an overridden base class method in a derived class, as
super does in other languages.
This is usually done so that a derived class method can augment a base class one by calling it before or after its own code, rather than completely replacing it.
class Derived(Base): def method(self, arg): # Maybe do something here super(Derived, self).method(arg) # Could so something here as well
super() function actually works by returning an object of a proxy class that delegates calls to the parent.
The advantage of using
super() in this case is that you don’t need to explicitly name the base class, which aids maintainability.
super() function can also be used in more complex multiple inheritance situations, where it can do things like delegate to a sister class.
These uses of
super are described in Python’s super() considered super!.