lqh 通过本文主要向大家介绍了python类详解,python开发技术详解,python os模块详解,python正则表达式详解,python 字典详解等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
Python 类的继承详解
Python既然是面向对象的,当然支持类的继承,Python实现类的继承比JavaScript简单。
Parent类:
class Parent:
parentAttr = 100
def __init__(self):
print("parent Init")
def parentMethod(self):
print("parentMethod")
def setAttr(self,attr):
self.parentAttr = attr
def getAttr(self):
print("ParentAttr:",Parent.parentAttr)
</div>
Child类
class Child(Parent):
def __init__(self):
print("child init")
def childMethod(self):
print("childMethod")
</div>
调用
p1 = Parent(); p1.parentMethod(); c1 = Child(); c1.childMethod();</div>
输出:
parent Init parentMethod child init childMethod Press any key to continue . . .</div>
Python支持多继承
class A: # 定义类 A ..... class B: # 定义类 B ..... class C(A, B): # 继承类 A 和 B .....</div>
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
</div>
