首页 > 编程语言 > 详细

python:practice module generator of list time jison

时间:2020-03-16 12:39:06      阅读:56      评论:0      收藏:0      [点我收藏+]

content:

1:generator of list【】:
list=[x for x in range(10)]
realize:[0,1,2,3,4,5,6,7,8,9]
list=[x*2 for x in range(10)]
list=[x*x for x in range(10)]
principal function:
def f(n):
return n**3
a=[f(x) for x in range(10)]
print(a)

a=(f(x) for x in range(10))

next(a)=a.__next__()
call the generator value
invoking generator value
generator is a iterable
invoke "for loop" express generator value
for i in a:
print(i)
for equivalent next() call generator
2: create generator main two method
use ()
ues yield
for example
def generator():
yield 7

generator()
can use for loop object
have __iter__method is object set() list[],dict{},tuple(),generator()

python:practice module generator of list time jison

原文:https://www.cnblogs.com/alansuny/p/12502986.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!