count() 的语法
-
itertools.count(start,step)函数的意思是创建一个从start开始每次的步长是step的无穷序列
-
如当count()括号里为空时,表示从0开始,每次步长为1
测试count函数用法
from itertools import count for i in count(1, 2): # 从1开始, 步长为2 print(i) if (i == 100 | i == 101): break
结果输出
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101