为了账号安全,请及时绑定邮箱和手机立即绑定

求助。以下代码有什么错误?

求助。以下代码有什么错误?

ST菜煎饼 2015-12-10 17:28:57
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


初始化是双下划线

查看完整回答
反对 回复 2015-12-10
  • 1 回答
  • 0 关注
  • 1443 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号