Single Inheritance
Create child classes that inherit attributes and methods from a parent.
Single Inheritance is a free Python Academy lesson on CoddyKit. This is 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, and your progress syncs across the web and the CoddyKit app. The Python Academy course includes 4 lessons in total.
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
Learn Python with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 76
- Lessons
- 320
Frequently Asked Questions
Is the “Single Inheritance” lesson free?
Yes — the full text of “Single Inheritance” is free to read here on the web. 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. The Python Academy course includes 4 lessons in total.
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, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 4.
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.
All lessons in this course
- Single Inheritance
- Method Overriding and super()
- Multiple Inheritance and MRO
- Polymorphism and Duck Typing