python多继承的两种情况

经典类,多类继承深度优先
class A():
def test(self):
print 'A xiazheng'

class B(A):
def test(self):
print 'B xiazheng'

class C(A):
def test(self):
print 'C xiazheng'

class D(B, C):
def test(self):
print 'D xiazheng'

a = D()
a.test()

查找顺序:D --> B --> A --> C

新式类,多类继承广度优先
class A(object):
def test(self):
print 'A xiazheng'

class B(A):
def test(self):
print 'B xiazheng'

class C(A):
def test(self):
print 'C xiazheng'

class D(B, C):
def test(self):
print 'D xiazheng'

a = D()
a.test()

查找顺序:D --> B --> C --> A

猜你喜欢

转载自www.cnblogs.com/Mr-ning/p/10370895.html
今日推荐