循环,range,continue 和 break
1、for循环
用户按照顺序循环可迭代对象中的内容,
PS:break、continue
1 li = [11,22,33,44] 2 for item in li: 3 print item
2、enumrate
为可迭代的对象添加序号
1 li = [11,22,33] 2 for k,v in enumerate(li, 1): 3 print(k,v)
3、range和xrange
指定范围,生成指定的数字
1 print range(1, 10) 2 # 结果:[1, 2, 3, 4, 5, 6, 7, 8, 9] 3 4 print range(1, 10, 2) 5 # 结果:[1, 3, 5, 7, 9] 6 7 print range(30, 0, -2) 8 # 结果:[30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2]