代码:
def data_iter(n):
for i in range(n):
yield (i*i,i*i*i)
for epoch in range(3):
print("++++++In for Loop++++++")
for a,b in data_iter(5):
print("a = ", a, end=" ")
print("b = ", b)
执行结果:
即使内循环结束,每次外循环都会从头开始调用迭代器