我会努力工作,提高测试技能。
TypeError: this constructor takes no arguments
上一篇 /
下一篇 2014-03-21 18:34:29
/ 个人分类:python学习
源码:
class Ball:
def _init_(self,size,color,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("red","small","down")
print myBall
运行:
>>> ================================ RESTART ================================
>>>
Traceback (most recent call last):
File "C:/Python27/learn/_str_.PY", line 12, in <module>
myBall = Ball("red","small","down")
TypeError: this constructor takes no arguments
问题:
init 和 str两边的下划线,英文应该是两个下划线。
收藏
举报
TAG: