|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- class Box():
- def setdimension(self, width, height, depth):
- def __init__(self, width, height, depth):
- self.width = width
- self.height = height
- self.depth = depth
- def getvolume(self):
- return self.width * self.height * self.depth
- b = Box(10, 20, 30)
- print(b.getvolume())
复制代码
pycharm里报了很多个错误
本帖最后由 hrp 于 2021-5-15 12:01 编辑
Box类没有重写__init__方法,实例化的时候不能传入参数
- class Box():
- def __init__(self, width, height, depth):
- self.width = width
- self.height = height
- self.depth = depth
-
- def getvolume(self):
- return self.width * self.height * self.depth
- b = Box(10, 20, 30)
- print(b.getvolume())
复制代码
|
|