Inheritance
Inheritance lets a subclass reuse and specialise a base class interface. Use it for a genuine substitutable relationship, not simply to share a few convenient lines.
Understand the idea
A subclass can override a method, while super can cooperate with base implementations. Composition is often clearer when one object merely uses another service. Keep the base contract small enough that every subclass can honour it without surprising callers or turning normal methods into unsupported operations.
Where to try it
Open this example with Try in playground. The code loads as editable text and does not run until you select Run. The first run downloads Python. Each run starts fresh; temporary files created by a script are not files on your PC.
A worked example
class Message:
def text(self):
return "Welcome"
class WorkshopMessage(Message):
def text(self):
return super().text() + " to Python"
print(WorkshopMessage().text())
Read the result
The output is Welcome to Python.
Try one change
Add a second subclass and check that a caller using text works without checking the concrete type.