When `Cat` has no `__init__` at all, how does Python still know how to build a cat — and which `__str__` wins when both classes define one?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
__init__Write a class named Cat whose header says a cat is an animal, and give it an empty body — pass is a complete body. Do not write an __init__, a getter, a setter or a __str__ anywhere inside it.
Then create a cat aged 5, give it the name "fluffy" using the method the parent already provides, and assign the cat object itself to cat.
class Animal(object):
def __init__(self, age):
self.age = age
self.name = None
def get_age(self):
return self.age
def get_name(self):
return self.name
def set_age(self, newage=0):
self.age = newage
def set_name(self, newname=""):
self.name = newname
def __str__(self):
return "animal:" + str(self.name) + ":" + str(self.age)