liveBook · Manning

Super keyword

As explained in The Well-Grounded Python Developer: How the pros use Python and Flask

super is a Python mechanism that provides access to methods and other attributes defined in a class's parent according to the method resolution order.

super() lets a child class call an initializer defined by its parent. It supports focused constructors: a Square accepts one size, then passes that value twice to Rectangle so inherited dimensions are initialized consistently. section 4.1.3

Use super() when a subclass specializes initialization without duplicating the parent’s setup:

  • A subclass can keep inherited behavior, such as Square using Rectangle.draw(), or override it when its rendering differs, as Circle does. section 4.1.3

Shape hierarchy

A Square supplies size instead of separate height and width, then delegates shared setup to Rectangle. A Circle delegates dimensions to Shape but defines its own drawing behavior.

How The Well-Grounded Python Developer: How the pros use Python and Flask covers it

How deep it goes
Explains parent-constructor delegation through Square and Circle examples, without detailing broader method-resolution behavior.
Examples
Uses Square, Rectangle, Shape, and Circle classes with delegated dimensions and shape-specific drawing.
What it assumes
Assumes familiarity with classes and inheritance while illustrating constructor delegation through shape examples.
What you can do after
Apply it via Python to reuse parent initialization while customizing subclass-specific parameters and behavior.
How it connects
Connects inheritance, constructors, class hierarchies, and method overriding.

Also explained in

Compare how 6 books explain super keyword →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Python Developer: How the pros use Python and Flask. The section links point to the parts of the book it draws on.