class Ball:
def _init_(self, color, size,direction):
self.color = color
self.size = size
self.direction = direction
def _str_(self):
msg = "Hi, I'm a " + self.size + "" +self.color + "ball!"
return msg
myBall = Ball("size", "small", "down")
print myBall运行时提示出错:Traceback (most recent call last): File "C:/Python27/dfkjdk.py", line 11, in <module> myBall = Ball("size", "small", "down")TypeError: this constructor takes no arguments帮忙看看有什么地方写错了。
1 回答
已采纳

何苦虐人心
TA贡献1条经验 获得超0个赞
class Ball:
def __init__(self, color, size,direction):
self.color = color
self.size = size
self.direction = direction
初始化是双下划线
添加回答
举报
0/150
提交
取消