Mixins
class FoodMixins(Person):
food = None
def get_food(self):
if self.food is None:
raise ValueError("Food should be set")
print(f"I like {self.food}")
class Person:
def hello(self):
print("I am Human")
# Первым вставляем миксину для расширения класса
class Student(FoodMixins, Person):
food = "Pizza"
def hello(self):
print("I am a student")
s = Student()
s.hello()
123456789101112131415161718192021Last updated