Python多继承子类的方法溯源规则

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
test = D()
test.save()

经典类的答案: This is from A

新式类的答案: This is from C

作者

Han

发布于

2018-03-23

更新于

2021-08-20

许可协议

评论