class A(object):
def __init__(self,a,b):
print a,b
def printA(self):
print"this is printA function"
class B(A):
def funB(self):
print "this B's fun function"
class C(A):
def funB(self):
print "here override B's funB function"
def funC(self):
print "this C's funC function"
class D(B,C):
pass
c = C()
c.funB()
新式类:直接或者间接(子类的父类,爷爷类..祖师爷类继承
object也算间接)继承object类称为新式类
Python2.7 中没有显式继承object就不是新式类,必须这样写:
class A(object)才是继承object类
Python3中默认继承object类
新式类的继承 查找 顺序是:广度优先
class D(object)
class C1(D)
class C2(D)
class B(C1,C2)
class A(B,C1,C2):继承 查找 顺序是:A->B->C1->C2->D->object
经典类的继承的 查找 顺序是:从左向右,深度优先
上面的class A(B,C1,C2)查找顺序是:A->B->C1(此处C1是指B继
承的C1)->D->object->C2