码迷,mamicode.com
首页 > 编程语言 > 详细

python:practice module generator of list time jison

时间:2020-03-16 13:03:28      阅读:63      评论:0      收藏:0      [点我收藏+]

标签:return   for loop   oop   invoke   exp   function   turn   res   practice   

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

标签:return   for loop   oop   invoke   exp   function   turn   res   practice   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!