鸭子类型:
当看到一只鸟走起来像鸭子、游泳起来像鸭子、叫起来像鸭子、叫起来也像鸭子、那么这只鸟就可以被称为鸭子
1 #!/user/bin/env python 2 # -*- coding:utf-8 -*- 3 4 5 class Cat(object): 6 7 @staticmethod 8 def say(): 9 print(‘i am cat‘) 10 11 12 class Dog(object): 13 14 @staticmethod 15 def say(): 16 print(‘i am dog‘) 17 18 19 class Duck(object): 20 21 @staticmethod 22 def say(): 23 print(‘i am duck‘) 24 25 26 animal_list = [Cat,Dog,Duck] 27 for animal in animal_list: 28 animal().say()
i am cat i am dog i am duck