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之后的所有语句,直接回到循环的顶端,提前进入下一次循环
原文地址:https://www.cnblogs.com/huangqiancun/p/8372082.html
时间: 2024-11-13 08:52:39