多重继承与鸭子类型

class Animal(object):
    def run(self):
        print("Animal is running")
class BarkMixIn(object):
    def bark(self):
        print('Barking...')

def run_twice(animal):
    animal.run()
    animal.run()

class Dog(Animal,BarkMixIn):
    def run(self):
        print('Dog is running')
dog=Dog()
dog.run()
dog.bark()

class Time():
    def run(self):
        print("start...")

run_twice(Time())

你可能感兴趣的:(多重继承与鸭子类型)