1.python 中的对象
属性 +方法=对象
class Ball: def bounce(self): if self.direction=="down": self.direction="up" myBall=Ball() myBall.direction="down" myBall.color="red" myBall.size="small" print "hellp" print "my ball is ",myBall.size print "my ball is",myBall.colormyBall.bounce()
2.init方法初始化对象
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","samll","down")