PythiloLesson 6 of 30 · progress kept in this browser

Inheritance and super()

A subclass can replace a parent's method or extend it. To extend, call the next version with super() and build on its result.

class Base:
    def tags(self):
        return ["base"]

class Logged(Base):
    def tags(self):
        return ["logged"] + super().tags()

class Cached(Base):
    def tags(self):
        return ["cached"] + super().tags()

class Service(Logged, Cached):
    pass

print(Service().tags())
print([c.__name__ for c in Service.__mro__])
Your task

Make Colored and Bordered cooperative: each __init__ takes keyword-only arguments, keeps its own (color="black", width=1) and passes the rest to super().__init__, and each describe extends super().describe(). Then Badge(name="ok", color="red", width=2).describe() returns ["ok", "2px", "red"].