Discuss / Python / 爹可以给儿子,儿子不可以给爹,不是一个爹看起来像爹也可以当干爹

爹可以给儿子,儿子不可以给爹,不是一个爹看起来像爹也可以当干爹

Topic source

1cfeng

#1 Created at ... [Delete] [Delete and Lock User]

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...')

class Timer(object): def run(self): print('Start...')

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

run_twice(animal()) run_twice(Tortoise()) run_twice(dog()) run_twice(cat()) run_twice(Timer())

兔子娃

#2 Created at ... [Delete] [Delete and Lock User]

run_twice(Timer()) start...
start... 不一定需要传入Animal类型,只需要保证传入的对象有一个run()方法就可以了。是这个意思吧!

神月宗

#3 Created at ... [Delete] [Delete and Lock User]

额...类名最好大写。比较好区分


  • 1

Reply