1、range()用来生成给定范围内的集合:
In [61]: for age in range(5): ...: print(age) ...: 0 1 2 3 4
2、range()函数还可以带步长作为第三个参数
In [62]: for age in range(5, 10 , 2): ...: print(age) ...: 5 7 9
3、Range()和len()组合,可以方便的变量列表
>>> a = ['Mary', 'had', 'a', 'little', 'lamb'] >>> for i in range(len(a)): ... print(i, a[i]) ... 0 Mary 1 had 2 a 3 little 4 lamb
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试