标签:面向 rom python python2 经典 div int 查找 class
例1:非菱形继承,经典类与新式类的属性查找顺序都一样
# class E:
# # def test(self):
# # print(‘from E‘)
# pass
#
# class F:
# def test(self):
# print(‘from F‘)
#
#
# class B(E):
# # def test(self):
# # print(‘from B‘)
# pass
#
# class C(F):
# def test(self):
# print(‘from C‘)
#
#
# class D:
# def test(self):
# print(‘from D‘)
#
#
# class A(B, C, D):
# # def test(self):
# # print(‘from A‘)
# pass
#
# obj=A()
# obj.test()
# 例2:菱形继承
class G(object): # 在python2中,未继承object的类及其子类,都是经典类
# def test(self):
# print(‘from G‘)
pass
class E(G):
# def test(self):
# print(‘from E‘)
pass
class F(G):
# def test(self):
# print(‘from F‘)
pass
class B(E):
# def test(self):
# print(‘from B‘)
pass
class C(F):
# def test(self):
# print(‘from C‘)
pass
class D(G):
# def test(self):
# print(‘from D‘)
pass
class A(B,C,D):
# def test(self):
# print(‘from A‘)
pass
# obj=A()
# obj.test()
print(A.mro())
面向对象之继承与派生
标签:面向 rom python python2 经典 div int 查找 class
原文地址:https://www.cnblogs.com/kylin5201314/p/13511735.html