在 Python 3.7 中,super
函数用于在多继承环境中访问父类。它接受两个参数:子类和当前类的对象,并返回一个代表父类的对象。例如:
class Shape:
def __init__(self, x, y):
self.x = x
self.y = y
def area(self):
return self.x * self.y
class Square(Shape):
def __init__(self, x):
super().__init__(x, x)
s = Squa