Discuss / Python / 打卡+理解(有误请指正)

打卡+理解(有误请指正)

Topic source

XERIN24040

#1 Created at ... [Delete] [Delete and Lock User]
def run_twice(anything):
    anything.run()
    anything.run()

只要你的anything类的方法里有run()就都可以运行;

像下面这行代码:

class people():
    def run(self):
        print("people do not extends Animal")
def run_twice(animal):
    animal.run()
    animal.run()
run_twice(people())

哪怕你第一行people不知道继承什么类(括号为空),只要你下面的方法里有run()就可以运行run_twice();

总而言之:只要你方法一样,你们就都是鸭子。

简而言之,人是鸭子[手动狗头]


  • 1

Reply