1.类的继承:
#/usr/bin/env #coding = utf-8 class animal(): def __init__(self,name): self.name=name def eat(self): print("%s eat food!" %self.name) class cat(animal): def cry(self): print("%s miaomiao jiao" %self.name) class dog(animal): def cry(self): print("%s wangwang jiao" %self.name) cat1 = cat(‘小猫‘) cat1.eat() cat1.cry() dog1 = dog(‘小狗‘) dog1.eat() dog1.cry()
结果:
小猫 eat food! 小猫 miaomiao jiao 小狗 eat food! 小狗 wangwang jiao
参考文档:https://www.cnblogs.com/wupeiqi/p/4493506.html
原文地址:https://www.cnblogs.com/solarzc/p/9363265.html
时间: 2024-11-02 12:29:02