多态
class Animal:
def bark(self):
pass
class Dog(Animal):
def bark(self):
print("原神,启动")
class Chicken(Animal):
def bark(self):
print("你干嘛,哎呀")
def make_noise(animal: Animal):
animal.bark()
dog = Dog()
chicken = Chicken()
make_noise(dog)
make_noise(chicken)
抽象类
class AC:
def cool_wind(self):
pass
def hot_wind(self):
pass
def swing_left_right(self):
pass
class Meidi_AC(AC):
def cool_wind(self):
print("美的制冷")
def hot_wind(self):
print("美的制热")
def swing_left_right(self):
print("美的左右摆动")
class DaJin_AC(AC):
def cool_wind(self):
print("大金制冷")
def hot_wind(self):
print("大金制热")
def swing_left_right(self):
print("大金左右摆动")
def make_cool(ac: AC):
ac.cool_wind()
meidi_ac = Meidi_AC()
dajin_ac = DaJin_AC()
make_cool(meidi_ac)
make_cool(dajin_ac)