Single Inheritance
Create child classes that inherit attributes and methods from a parent.
Single Inheritance is a free Python Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Python Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Introduction
Defining a Child Class
class Animal:
def __init__(self, name): self.name = name
def speak(self): return '...'
class Dog(Animal):
def speak(self): return 'Woof'
d = Dog('Rex')
print(d.name, d.speak())Calling super().__init__
class Animal:
def __init__(self, name): self.name = name
class Dog(Animal):
def __init__(self, name, breed):
super().__init__(name)
self.breed = breed
d = Dog('Rex', 'Labrador')
print(d.name, d.breed)Inheriting Methods
class Vehicle:
def start(self): return 'starting'
class Car(Vehicle):
pass
print(Car().start())Overriding Methods
class Shape:
def area(self): return 0
class Square(Shape):
def __init__(self, s): self.s = s
def area(self): return self.s**2
print(Square(4).area())Extending Parent Behavior
class Animal:
def describe(self): return 'I am an animal'
class Dog(Animal):
def describe(self): return super().describe() + ' and a dog'
print(Dog().describe())isinstance() and issubclass()
class Animal: pass
class Dog(Animal): pass
d = Dog()
print(isinstance(d, Animal))
print(issubclass(Dog, Animal))Child Adds New Methods
class Animal:
def __init__(self, name): self.name = name
class Dog(Animal):
def fetch(self): return f'{self.name} fetches!'
print(Dog('Rex').fetch())Protected Attributes
class Animal:
def __init__(self, name): self._name = name
def name(self): return self._name
class Dog(Animal):
def bark(self): return f'{self._name} barks'
print(Dog('Rex').bark())Abstract Base Classes
from abc import ABC, abstractmethod
class Shape(ABC):
@abstractmethod
def area(self): pass
class Circle(Shape):
def __init__(self, r): self.r = r
def area(self):
import math
return math.pi * self.r**2
print(Circle(3).area())__bases__ and __mro__
class A: pass
class B(A): pass
class C(B): pass
print(C.__mro__)Quick Check
Recap
Keep Going
Frequently asked questions
Is the “Single Inheritance” lesson free?
Yes — the full text of “Single Inheritance” is free to read here on the web, and the Python Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Python Academy course, upgrade to CoddyKit PRO.
What will I learn in “Single Inheritance”?
Create child classes that inherit attributes and methods from a parent. You practise Python Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Python Academy?
No prior experience is required. Python Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Single Inheritance” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Python Academy lesson?
Yes. Every Python Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.