python-何为鸭子模型
鸭子模型:一只鸟走起来像鸭子、游泳起来像鸭子、叫起来也像鸭子,那么这只鸟可以被称为鸭子
代码示例
class Cat(object):
def say(self):
print('i am is cat')
class Dog(object):
def say(self):
print('i am is dog')
class Duck(object):
def say(self):
print('i am is duck')
animal_list = [Cat, Dog, Duck]
for animal in animal_list:
animal().say()
共有 0 条评论