python 没有分号和大括号,中文注意加#coding:utf8
在Python中没有switch语句。您可以使用一个if..elif..else语句做同样的事(和在某些情况下,使用词典去做更快速)。
类class
采用__init__()来完成初始化
class Ball:
def __init__(self,color,size,direction):
self.color=color
self.size=size
self.direction=direction
def bounce(it):
if(it.direction== "down"):
it.direction="up"
myBall = Ball("red","small","down")
print "ball is ",myBall.size
print "ball is ",myBall.direction
myBall.bounce()#注意不需要传递参数了
print "ball is ",myBall.direction