yield的用法1、
listone = [['a','b','c'],['d','e'],['f','h', 'z', 'x']]
def transe():
for list_ele in listone:
for ele in list_ele:
yield ele
if __name__ == '__main__':
t = transe()
try:
while True:
print(t.__next__())
except StopIteration:
pass
yield用法2:
def gen(max):
a, b = 0,1
while a < max:
yield a
a, b = b, a+b
if __name__ == '__main__':
gg = gen(20)
try:
while True:
print(gg.__next__())
except StopIteration:
pass

被折叠的 条评论
为什么被折叠?



