标签: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