1 选择
if elif else
注意后面均有:
if age>18: print 'adult' elif age>6: print 'teenager' else: print 'kid'
2 循环
1) for x in xx:
names = ['Michael', 'Bob', 'Tracy'] for name in names: print name
2)while xx:
sum = 0 n = 99 while n > 0: sum = sum + n n = n - 2 print sum
3)高级range(a,b,c),a起始,b终止(不包括b),c步长
print sum(range(1,100,2))
3 break和continue
break使整个循环提前结束
continue终止本次循环,忽略continue之后的所有语句,直接回到循环的顶端,提前进入下一次循环
作者:huangqiancun
出处:http://www.cnblogs.com/huangqiancun/
本博客若无特殊说明则由作者原创发布,欢迎转载,但请注明出处 :)