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