是否有人可以向我解释为什么在“with”和“without”之间打印我的序列代码时出现差异for loop?发电机 - 打印生成的值
def generation(x):
i = 0
while i < x:
yield i
i += 1
x = generation(10)
print("Print without for loop: " + str(x))
print("Print with for loop: ")
for j in x:
print(j)
生成器基本上是惰性迭代器。 – erip
尝试'print(“打印没有for循环:”,* x)' –
请参阅https://stackoverflow.com/questions/1756096/understanding-generators-in-python –