python类与函数的用法,下面程序错在哪?
classBall:def_init(self,color,size,direction):self.color=colorself.size=sizeself.dire...
class Ball:
def _init(self,color,size,direction):
self.color=color
self.size=size
self.direction=direction
def bounce(self):
if self.direction=='down':
self.direction='up'
myBall=Ball("red","small","down")
print ' set a ball'
print 'ball color=',myball.color
print 'ball size=',myball.size
print 'ball diretion=',myball.direction
myball.bounce()
print 'ball direction=',myball.direction
Traceback (most recent call last):
File "D:/Program Files/python/123python/0725/003", line 10, in <module>
myBall=Ball("red","small","down")
TypeError: this constructor takes no arguments 展开
def _init(self,color,size,direction):
self.color=color
self.size=size
self.direction=direction
def bounce(self):
if self.direction=='down':
self.direction='up'
myBall=Ball("red","small","down")
print ' set a ball'
print 'ball color=',myball.color
print 'ball size=',myball.size
print 'ball diretion=',myball.direction
myball.bounce()
print 'ball direction=',myball.direction
Traceback (most recent call last):
File "D:/Program Files/python/123python/0725/003", line 10, in <module>
myBall=Ball("red","small","down")
TypeError: this constructor takes no arguments 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询