__str__ from its parent, and a third class extends it with super().
class Animal:
sound = "..."
def __str__(self):
return f"{type(self).__name__} says {self.sound}"
class Cat(Animal):
sound = "meow"
class Kitten(Cat):
def __str__(self):
return "small " + super().__str__()
print(Cat(), Kitten(), sep=" | ")
What does the program print?Log in to join the discussion.
Loading…