# Animal # base class class Animal: def __init__(self, name, age): self.name = name self.age = age def preview(self): print(f"{self.name} is a {self.creature} of {self.age} years old") # Dog # extends Animal class Dog(Animal): voice = 'woof! ~@_@~' def __init__(self, name, age): self.name = name self.age = age self.creature = 'dog' def speak(self): print(self.voice) # Cat # extends Animal class Cat(Animal): voice = 'meao!! >^_^<' def __init__(self, name, age): self.name = name self.age = age self.creature = 'cat' def speak(self): print(self.voice) # functions # --- -- -- - - - def newLine(): print(" ") def attrs(obj): for attribute, value in obj.__dict__.items(): print(f"{attribute}: {value}") # instances # --- -- -- - - - d = Dog('Ersi', 8) r = Cat('Riri', 10) d.preview() d.speak() attrs(d) newLine() r.preview() r.speak() attrs(r)