class A:
def __init__(self):
# super().__init__()
print("FishA")
class B:
def __init__(self):
# super().__init__()
print("FishB")
class C(A):
def __init__(self, arg):
super().__init__()
print("FishC")
class D(B):
def __init__(self, arg):
super().__init__()
print("FishD")
class E(C, D):
def __init__(self, arg):
super().__init__(arg)
print("FishE")
参数arg不能传递到c和d?
class A:
def __init__(self,arg):
super().__init__(arg)
print("FishA")
class B:
def __init__(self):
super().__init__()
print("FishB")
class C(A):
def __init__(self, arg):
super().__init__(arg)
print("FishC")
class D(B):
def __init__(self, arg):
super().__init__()
print("FishD")
class E(C, D):
def __init__(self, arg):
super().__init__(arg)
print("FishE")
e = E(520)
不懂
没传参数
03行会提示缺少参数"arg"
所以多继承传参数是不是不能用super()?因为这样单独使用父类实例的时候会因参数不匹配而出问题
学习
想知道答案
1
{:10_258:}
{:5_108:}
0728
Hi
第三个例子(见下图),B1 和 A 处于同一侧,并且 A 和 B2 都拥有同一个父类(object),所以 (B1, A) 和 B2 处于同一级。
^
此处"三"改为"二"
按照 DFLR 规则,左侧优先、深度优先,所以是 B1 -> A -> B2
class A:
def __init__(self):
super().__init__(520)
print("FishA")
class B:
def __init__(self):
super().__init__()
print("FishB")
class C(A):
def __init__(self, arg):
super().__init__()
print("FishC")
class D(B):
def __init__(self, arg):
super().__init__()
print("FishD")
class E(C, D):
def __init__(self, arg):
super().__init__(arg)
print("FishE")
e = E(520)
结果:
FishB
FishD
FishA
FishC
FishE
ok、
问题在哪
难道不是B类没有父类,super函数没法用了么??