【发布时间】:2020-04-20 10:37:42
【问题描述】:
如果我这样编码,为什么我的程序可以工作:
class Shape:
class Shape:
shape_type = ""
def __init__(self, c='*'):
self.color = c
class Square(Shape):
shape_type = "Quadrat"
def __init__(self, w, *args, **kwargs):
Shape.__init__(self, *args, **kwargs)
self._width = w
q1 = Square(4, c="#")
但如果我使用 super() 函数则不会
class Shape:
shape_type = ""
def __init__(self, c='*'):
self.color = c
class Square(Shape):
shape_type = "Quadrat"
def __init__(self, w, *args, **kwargs):
super().__init__(self, *args, **kwargs)
self._width = w
q1 = Square(4, c="#")
它说 TypeError: init() got multiple values for argument 'c'.
【问题讨论】:
标签: python class object arguments super