Python继承和多态
程序员文章站
2022-03-29 19:47:20
Python继承与多态,程序测试一个动物类,两个子类Dog、Cat。def run_twice(animal): animal.run() animal.run() class Animal(object): def run(self): print('Animal is running') #动物... ......
python继承与多态,程序测试一个动物类,两个子类dog、cat。
def run_twice(animal): animal.run() animal.run() class animal(object): def run(self): print('animal is running') #动物类 class dog(animal): def run(self): print('dog is running...') def eat(self): print('eating meat...') #狗类 class cat(animal): def run(self): print('cat is running') #猫类 dog = dog() dog.run() dog.eat() cat = cat() cat.run() run_twice(dog())
读书和健身总有一个在路上