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

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

帮忙看看有什么地方写错了。

ST菜煎饼
浏览 1444回答 1
1回答

何苦虐人心

class Ball:    def __init__(self, color, size,direction):        self.color = color        self.size = size        self.direction = direction初始化是双下划线
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python