python3 多态与多态性

lass Animal:
    def talk(self):
        pass

class People(Animal):
    def talk(self):
        print('say hello')
class Pig(Animal):
    def talk(self):
        print('say aoao')

class Dog(Animal):
    def talk(self):
        print('say wangwang')

class Cat(Animal):
    def talk(self):
        print('cat talking')

p1=People()
pig1=Pig()
D1=Dog()
c=Cat()

  

s='xxx'
l=[1,2,3]
t=(4,5,6)

#多态性
def func(obj):
    print(obj.__len__())

func(s)
func(l)
func(t)

>> 打印
3
3
3

  

posted @ 2017-03-10 11:35  没有为什么  阅读(307)  评论(0编辑  收藏  举报