当我创建如下的父类和子类时,为什么子类不会自动继承父类的参数?
我明白显式更好,但我想知道在什么情况下这段代码...
我明白显式更好,但我想知道在什么情况下这段代码...
class testParent(object):
def __init__(self,testParentParam1,testParentParam2):
pass
class testChild(testParent):
def __init__(self,testParentParam1,testParentParam2,testChildParam1,testChildParam2):
pass
比这段代码更好...
class testParent(object):
def __init__(self,testParentParam1,testParentParam2):
pass
class testChild(testParent):
def __init__(self,testChildParam1,testChildParam2):
pass
__init__
)接受了与超类相同的参数并将它们未经修改地传递下去。大多数子类接受较少的参数或不同的参数(并以某种方式计算要传递给超类的参数)。 - user395760