Skip to content
Learn Netverks

Lesson

Step 19/36 53% through track

inheritance-python

Inheritance

Last reviewed May 28, 2026 Content v20260528
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Inheritance: the syntax, patterns, and safety habits you need before advancing in Python.

Teams still ship Inheritance in Python codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Inheritance in contexts like: Scripts, Django/FastAPI apps, notebooks, and glue code between systems.

Write Python 3 in the editor and click Run on server—the dev runner executes your script with print() for output; stdlib only in playground snippets (LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Python supports single inheritance with optional multiple inheritance—use sparingly. Subclasses override methods; call super with super() to extend parent behavior—like Java super or C# base.

Subclass example

class Animal:
    def speak(self):
        return "..."

class Dog(Animal):
    def speak(self):
        return "woof"

class ServiceDog(Dog):
    def speak(self):
        base = super().speak()
        return f"{base} (trained)"

Method Resolution Order (MRO)

Python uses C3 linearization for MRO—ClassName.__mro__ shows lookup order in multiple inheritance. Prefer composition over deep inheritance trees.

Important interview questions and answers

  1. Q: super() purpose?
    A: Delegates to the next class in MRO—works with multiple inheritance unlike hard-coded parent names.
  2. Q: Composition vs inheritance?
    A: Favor has-a relationships when behavior can be shared without is-a taxonomies—especially in Django models later.

Self-check

  1. How call a parent method from a subclass?
  2. What does MRO stand for?

Pitfall: Deep inheritance hierarchies hurt maintenance—prefer composition for shared behavior.

Interview prep

super() purpose?

Calls next method in MRO—supports cooperative multiple inheritance.

Composition vs inheritance?

Prefer has-a when behavior sharing does not imply is-a taxonomy—especially in large apps.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • MRO idea?
  • super() use?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump