函数-函数进阶-生成器调用方法

>>> a = (i for i in range(10))
>>> while True:
...  print(next(a))
...
0
1
2
3
4
5
6
7
8
9
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
StopIteration
>>>

>>> a = (i for i in range(10))
>>> for i in a:
...  print(i)
...
0
1
2
3
4
5
6
7
8
9
>>>

python 2

  range = list

  xrange = 生成器

python3

  range = 生成器

  xrange = 没有

原文地址:https://www.cnblogs.com/kingforn/p/10937655.html