Calling the parent __init__ with super()

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Calling the parent __init__ with super()

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line inside Dog's __init__ runs the parent Animal's setup?
A super().__init__(name)
B super.init(name)
2. A child class has its own __init__ and never calls super().__init__(). What happens to the parent's attributes?
A They are not set up on the new object
B Python sets them up automatically
3. Parent: class Vehicle with __init__(self, make). Which child call passes the argument correctly?
A super().__init__(self, make)
B super().__init__(make)
4. Where should super().__init__(...) usually go in the child's __init__?
A First, before the child-only attributes
B Last, after all the child-only attributes
5. Car's __init__(self, make, doors) calls super().__init__(make). Where does self.doors = doors belong?
A In Vehicle's __init__, as it is shared
B In Car's __init__, after the super() call

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1super().__init__(name, age) AThe child sets its own attribute before calling the parent's __init__. Call super().__init__() first so the inherited setup runs before the child adds its own attributes.
2super().describe() Bclass Student(Person):
3A child class runs the parent's setup first, then adds an attribute that only the child has Cself is passed explicitly to super().__init__(). super() already supplies self, so it should be super().__init__(name).
4A child class declares that it inherits from a parent class named Person DCalls the parent class's version of an overridden method from inside the child class
5def __init__(self, name, year): self.year = year super().__init__(name) Edef __init__(self, name, wage): super().__init__(name) self.wage = wage
6super().__init__(self, name) FPasses name and age up to the parent class's __init__ so it sets up the inherited attributes

Definitions

super().__init__()

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
super().________(name) self.breed = breed
2.
def describe(self): _____().describe() print("Breed:", self.breed)
3.
def describe(self, prefix): super().describe(______)
4.
# child-only attribute self.____ = team
5.
def describe(self): super().________() print("Breed:", self.breed)

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A class Dog(Animal):
B def __init__(self):
C super().__init__(name)
D self.tricks = []
Question 2
A class Car:
B def __init__(self, brand):
C super().__init__(brand)
D self.doors = 4
Question 3
A class Person:
B def __init__(self, name)
C self.name = name
D class Staff(Person):
E def __init__(self, name):
F super().__init__(name)
Question 4
A class Student(Person):
B def __init__(self, name, id):
C super.__init__(name)
D self.id = id
Question 5
A class Animal:
B def __init__(name):
C self.name = name
D class Fish(Animal):
E def __init__(self, name):
F super().__init__(name)

Answer Key

Calling the parent __init__ with super()
Section A: Quick Questions
Q1
A — super().__init__(name)
Q2
A — They are not set up on the new object
Q3
B — super().__init__(make)
Q4
A — First, before the child-only attributes
Q5
B — In Car's __init__, after the super() call
Section B: Match the Pairs
Q1
super().__init__(name, age) → Passes name and age up to the parent class's __init__ so it sets up the inherited attributes
Q2
super().describe() → Calls the parent class's version of an overridden method from inside the child class
Q3
A child class runs the parent's setup first, then adds an attribute that only the child has → def __init__(self, name, wage): super().__init__(name) self.wage = wage
Q4
A child class declares that it inherits from a parent class named Person → class Student(Person):
Q5
def __init__(self, name, year): self.year = year super().__init__(name) → The child sets its own attribute before calling the parent's __init__. Call super().__init__() first so the inherited setup runs before the child adds its own attributes.
Q6
super().__init__(self, name) → self is passed explicitly to super().__init__(). super() already supplies self, so it should be super().__init__(name).
Section C: Definitions
Q1
super().__init__() — Runs the parent class's __init__ first so it sets up inherited attributes, then the child's __init__ adds its own extra attributes.
Section D: Fill in the Blanks
Q1
super().__init__(name) self.breed = breed
Q2
def describe(self): super().describe() print("Breed:", self.breed)
Q3
def describe(self, prefix): super().describe(prefix)
Q4
# child-only attribute self.team = team
Q5
def describe(self): super().describe() print("Breed:", self.breed)
Section E: Spot the Error
Q1
B — The child __init__ must accept name so it can pass it up to the parent with super().__init__(name). Without the name parameter, name is undefined on the next line. It should be def __init__(self, name):
Q2
A — Car must list Vehicle in brackets to inherit from it. Without a parent class, super().__init__(brand) has no Vehicle setup to run. It should be class Car(Vehicle):
Q3
B — A def line must end with a colon. Without it Python raises a SyntaxError and the parent setup never exists. It should be def __init__(self, name):
Q4
C — super needs brackets: super() gives access to the parent class. Writing super without () refers to the built-in type itself and fails. It should be super().__init__(name)
Q5
B — Every instance method, including __init__, must have self as its first parameter. Without self, the name argument is wrongly taken as the object. It should be def __init__(self, name):