generator:生成器
示例:
def generator(N):
for i in range(N):
yield i ** 2
for i in generator(10):
print(i)
type(generator(10))
0
1
4
9
16
25
36
49
64
81
<class 'generator'>
generator:生成器
示例:
def generator(N):
for i in range(N):
yield i ** 2
for i in generator(10):
print(i)
type(generator(10))
0
1
4
9
16
25
36
49
64
81
<class 'generator'>
本文标题:Python 生成器
本文链接:https://www.haomeiwen.com/subject/vwtraqtx.html
网友评论