def demo():
for i in range(4):
yield i
g=demo()
g1=(i for i in g)
g2=(i for i in g1)
print(list(g1))
print(list(g2))
打印结果:
[0, 1, 2, 3]
[]
def demo():
for i in range(4):
yield i
g=demo()
g1=(i for i in g)
g2=(i for i in g1)
print(list(g))
print(list(g1))
print(list(g2))
打印结果:
[0, 1, 2, 3]
[]
[]
def demo():
for i in range(4):
yield i
g=demo()
g1=(i for i in g)
g2=(i for i in g1)
print(list(g2))
打印结果:
[0, 1, 2, 3]
执行顺序问题,引以为鉴