2009年5月4日 星期一

Assign values simultaenous

指定變數 x,y,z 均為0
x=y=z=0
print("x now is "+str(x))
print("y now is "+str(y))
print("z now is "+str(z))

定義變數 a,b
a=1
b=2
指定變數值
a,b=b,a

print("a now is "+str(a))
print("b now is "+str(b))

結果
x now is 0
y now is 0
z now is 0
a now is 2
b now is 1

沒有留言:

張貼留言