python 类的继承
2021/9/12 22:34:54
本文主要是介绍python 类的继承,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
class Ctc(object): def __init__(self): self.name = "shun" def run(self): self.prea() self.a() self.b() self.c() def a(self): print("a") def b(self): print("b") def prea(self): print("Prea") class TestInstance(Ctc): def __init__(self): self.name = "shun2" def a(self): print("aa") def b(self): print("bb") class Another(TestInstance): def __init__(self): self.name = "another" def a(self): print("aa in Another") # def b(self): # print("bb in Another") def d(self): print("d in Another") class Case(Another): def __init__(self): self.name = "shun3" def c(self): print("cc in case") # def b(self): # print("bbb") # def run(self): # print("run in case") if __name__ == '__main__': test = Case() exit(test.run())
类的继承,会先找最底层的类是否有此函数,在找最接接近的类,直到最上层父类,就近原则
这篇关于python 类的继承的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-03用FastAPI掌握Python异步IO:轻松实现高并发网络请求处理
- 2025-01-02封装学习:Python面向对象编程基础教程
- 2024-12-28Python编程基础教程
- 2024-12-27Python编程入门指南
- 2024-12-27Python编程基础
- 2024-12-27Python编程基础教程
- 2024-12-27Python编程基础指南
- 2024-12-24Python编程入门指南
- 2024-12-24Python编程基础入门
- 2024-12-24Python编程基础:变量与数据类型