class Ball:
def bounce(self):
if self.direction == "down":
self.direction = "up"
myBall = Ball()
myBall.direction = "down"
myBall.color = "red"
myBall.size = "small"
print "I just created a ball."
print "My ball is", myBall.size
print "My ball is", myBall.color
print "My ball's direction is", myBall.direction
print "Now I'm going to bounce the ball"
myBall.bounce()
print "Now the ball's direction is", myBall.direction
在倒数第二行调用函数。“myBall.bounce() ”
myBall是不是参数?如果不是该怎么理解?如果是为什么参数没有放进括号里面。
还有定义函数的代码下面,“myBall = Ball() ”
这是不是在设置参数?如果是的话为什么Ball后面加括号?