面向对象-多态
多态
#多态,它指的是一类事物有多种形态
class Animal:
def voice(self):
pass
class cow(Animal):
def voice(self):
print('咩咩咩???')
class mice(Animal):
def voice(self):
print('吱吱吱')
c = cow()
c.voice()
m = mice()
m.voice()
#或者统一接口
def call(obj):
obj.voice()
call(m)
call(c)
说明:使用多态,让程序更灵活。增加了程序的拓展性

浙公网安备 33010602011771号