新手求助
class rectangle:def __init__(self, length, width):
self.length = length
self.width = width
def s(self):
return length * width
class square(rectangle):
def __init__(self, length):
self.length = length
self.width = length
a = square(5, 5)
print(a.s)
这段代码有什么问题呢? class rectangle:
def __init__(self, length, width):
self.length = length
self.width = width
def s(self):
return self.length * self.width#少了两个self
class square(rectangle):
def __init__(self, length, width): #少了width参数
self.length = length
self.width = length
a = square(5, 5)
print(a.s()) # 方法调用少了括号 修改一下:
class rectangle:
def __init__(self, length, width):
self.length = length
self.width = width
def s(self):
return self.length * self.width
class square(rectangle):
def __init__(self, length):
self.length = length
self.width = length
a = square(5)
print(a.s())
页:
[1]