Skip to content
UPEEC

Method Overriding

A subclass replaces a parent method with its own version, optionally calling the parent via super().

Easy
Comments 0
class Sensor:
    def read(self): return 0
class FilteredSensor(Sensor):
    def read(self):
        raw = super().read()
        return round(raw, 2)

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.