python 生成器
# 生成器表达式,生成可迭代对象,不能反复迭代(延迟求值,惰性求值)
tmp = (x for x in range(9))
print(type(tmp))
print(next(tmp)) # 结果:0
print(next(tmp)) # 结果:1
for i in tmp: # 循环迭代不容易出现边界错误
print(i)
# 生成器表达式,生成可迭代对象,不能反复迭代(延迟求值,惰性求值)
tmp = (x for x in range(9))
print(type(tmp))
print(next(tmp)) # 结果:0
print(next(tmp)) # 结果:1
for i in tmp: # 循环迭代不容易出现边界错误
print(i)