生成器

"""生成器:边执行边运算---惰性运算:节省空间"""
"""python 2 会先生成这些数据 range()"""
for i in range(1000):
    print(i)
    if i>100:
        break
"""while循环也是在运算过程中生成下一个值"""
count=0
while count <100000:
    print(count)
    count +=1
    if count >100:
        break
"""迭代器"""
g=(x * x for x in range(10))
print(next(g))
print(next(g))

 

posted @ 2020-06-20 22:58  行走的小z  阅读(87)  评论(0编辑  收藏  举报