← Python from Scratch Lesson 68 of 78 · 5 XP

Warm-up: a child class warm-up

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

A child class gets all the parent's methods and can add its own. The parent is written in brackets after the class name:

class Animal:
    def eat(self):
        return "Eating"

class Bird(Animal):       # Bird is a child of Animal
    def fly(self):
        return "Flying"

b = Bird()
print(b.eat())   # Eating — the method came from the parent

Task. The Animal class is already there. Create a child class Bird with a method fly() that returns Flying.

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.