Inheritance = Inherit attributes and methods from another class
Helps with code reusability and extensibility
class Child(Parent)
class Animal:
def __init__(self, name):
self.name = name
self.is_alive = True
def eat(self):
print(f"{self.name} is eating")
def sleep(self):
print(f"{self.name} is asleep")
class Dog(Animal):
def speak(self):
print("WOOF!")
class Cat(Animal):
def speak(self):
print("MEOW!")
class Mouse(Animal):
def speak(self):
print("SQUEEK!")
dog = Dog("Scooby")
cat = Cat("Garfield")
mouse = Mouse("Mickey")
Смотрите видео Python INHERITANCE in 6 minutes! 👨👦👦 онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Bro Code 24 Май 2024, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 7,911 раз и оно понравилось 225 людям.