CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
jackfrued

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: jackfrued/Python-100-Days
Path: blob/master/Day01-15/code/Day13/generator1.py
Views: 729
1
"""
2
生成器 - 生成器语法
3
4
Version: 0.1
5
Author: 骆昊
6
Date: 2018-03-21
7
"""
8
9
seq = [x * x for x in range(10)]
10
print(seq)
11
12
gen = (x * x for x in range(10))
13
print(gen)
14
for x in gen:
15
print(x)
16
17
num = 10
18
gen = (x ** y for x, y in zip(range(1, num), range(num - 1, 0, -1)))
19
print(gen)
20
n = 1
21
while n < num:
22
print(next(gen))
23
n += 1
24
25