if语句
num = 10
if num > 1 :
print 'wrong'
else :
print 'right'
if x:
print 'True' #只要x为非零数值,非空字符串,非空list等,就判断为True,否则为False
循环
names = ['zhoujilun', 'fanbingbing', 'lichen']
for name in names :
print name
结果:
zhoujilun
fanbingbing
lichen
求1到10的整数和
sum = 0
for x in range(11) :
sum = sum + x
print sum
while循环
sum = 0
while n > 0
sum = sum + n
n = n - 2
print sum
在循环内部变量n不段字减,直到为-1是跳出循环