次の code.py ファイルがあります。
class Shape:
def __init__(self, x, y):
self.x = x
self.y = y
def move(self, delta_x, delta_y):
self.x += delta_x
self.y += delta_y
class Square(Shape):
def __init__(self, side=1, x=0, y=0):
super().__init__(x, y)
self.side = side
class Circle(Shape):
def __init__(self, rad=1, x=0, y=0):
super().__init__(x, y)
self.radius = rad
次のように Python インタープリターでコードを実行しています。
>>> import code
>>> c = code.Circle(1)
次のエラーが表示されます。
Traceback (most recent call last):<br>
...<br>
File "code.py", line 18, in __init__<br>
super().__init__(x, y)<br>
TypeError: super() takes at least 1 argument (0 given)<br>
このエラーが発生する理由がわかりません。rad 値 1 を指定していますが、x と y の値を指定していないため、Circle はデフォルト値の x=0 と y=0 を使用し、super() を介して Shape に渡す必要があると想定します。関数。私は何が欠けていますか?
ところで、私は Python 2.7.1 を使用しています。
ありがとう。