Initialising subclasses with super()

Beginner Python OOP Inheritance
Created by Pavel · 07.03.2026 at 19:57 UTC · 5 completed

Sensors share an identifier and a readings buffer; a temperature sensor adds a unit string. If the child __init__ forgets super().__init__(...), the parent fields never appear and every later method assumes a broken object.

super() is the cooperative spelling: it respects MRO, which matters the moment you mix in another base. Hard-coding Sensor.__init__(self, ...) in one child often breaks when the hierarchy grows.

University approvals: 0
Tasks
Question 1

What is the recommended way to call a parent class constructor?

Hint

It respects method resolution order

Question 2

Sensor with __init__(self, sensor_id) setting self.sensor_id and self.readings = [].
TemperatureSensor(Sensor) with __init__(self, sensor_id, unit) calling super().__init__(sensor_id) and self.unit = unit.
t = TemperatureSensor("S42", "°C") then print(t.sensor_id, t.unit).

Expected stdout: S42 °C (space-separated).

Hint

print two attributes separated by a space.

Starter code is prefilled; replace TODO blocks with your solution.
1 test case will be used for grading
Run checks runtime behavior only. Final correctness is evaluated when you submit.
Card Info
  • Topic: Python OOP Inheritance
  • Difficulty: Beginner
  • Completed: 5 users
Creator
Pavel
Pavel