因为我用的是python3,所以所用到的类都是新式类,这里我说的都是新式类,python2类的继承复杂一些,主要有新式类和老式类。python3类(新式类)的继承是是广度优先(BFS),实例如下:
class A(): def __init__(self): pass def save(self): print("This is from A") class B(A): def __init__(self): pass class C(A): def __init__(self): pass def save(self): print("This is from C") class D(B,C): def __init__(self): pass fun = D() fun.save()
执行结果为:This is from C
题外话,python2只在有显式继承了Object的类才是新式类,没有显式继承Object的类是经典类,经典类的多继承是深度优先(DFS),如果是经典类,控制台输出应该为:This is from A