Python Inheritance
class Animal:
def __init__(self, name):
self.name = nameclass Dog(Animal):
def __init__(self, name, breed):
super().__init__(name)
self.breed = breedThe super() function is used to call the constructor of the parent class, allowing you to initialize inherited attributes and methods.
mydog = Dog("Name", "Breed")class Cat(Animal):
def __init__(self, name, color):
super().__init__(name)
self.color = color
def meow(self):
return "Meow!"mycat = Cat("Whiskers", "Tabby")
mycat.meow()'Meow!'
class Kitten(Cat):
def __init__(self, name, color, age):
super().__init__(name, color)
self.age = age
def purr(self):
return "Purr!"kitty = Kitten("Fluffy", "White", 1)
kitty.meow(); kitty.purr()'Purr!'