Discuss / Python / 学习小记

学习小记

Topic source

class Animal(object):

    def run(self):

        print('Animal is running....')

class Dog(Animal):

    def run(self):

        print('Dog is running....')

class Cat(Animal):

    def run(self):

        print('Cat is running')

class Tortoise(Animal):

    def run(self):

        print('Tortoise is running slowly....')

def runTwice(animal):

    animal.run()

    animal.run()

#不是动物类,但是有相同的run方法

class ABC(object):

    def run(self):

        print('hello,world')

an=Animal()

an1=Dog()

an2=Cat()

an3=Tortoise()

abc=ABC()

an.run()

an1.run()

an2.run()

an3.run()

abc.run()

runTwice(an)

runTwice(an1)

runTwice(an2)

runTwice(an3)

runTwice(abc)

输出。。。。。。。。。。。。。。。。。。。。

Animal is running....

Dog is running....

Cat is running

Tortoise is running slowly....

hello,world

Animal is running....

Animal is running....

Dog is running....

Dog is running....

Cat is running

Cat is running

Tortoise is running slowly....

Tortoise is running slowly....

hello,world

hello,world

不是动物类,但是有相同的run方法,是指相print方法?


  • 1

Reply