Python 经典类和新式类

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# 作者:Presley
# 邮箱:[email protected]
# 时间:2018-10-21
# 新式类和经典类

class A:
n = "A"
def f2(self):
print("from A")

class B(A):
n = "B"
def f1(self):
print("from B")
# def f2(self):
# print("f2 from B")

class C(A):
n = "C"
def f2(self):
print("from C")

class D(B,C):
pass

d = D()
d.f1()
d.f2()#按照先去找B,没有的话再去找C,C没有的话再去找A。按照广度优先的原则

#在老版本中经典类按照深度优先,新式类按照广度优先,但是在3.0后无论经典类还是新式类全都按照广度优先,因此上图虽然是经典类但是还是广度优先

猜你喜欢

转载自www.cnblogs.com/Presley-lpc/p/9826346.html