Discuss / Python / 函数+列表生成式 构成生成器

函数+列表生成式 构成生成器

Topic source

花泽的类

#1 Created at ... [Delete] [Delete and Lock User]

-- coding: utf-8 -- def triangles(): L=[1] while 1: #即while True: 一直循环生成无限临时数据 yield L L = [L[i-1] + L[i ] for i in range(1,len(L))]
L.insert(0, 1)
L.append(1)

n = 0 for x in triangles(): print(str.center(str(x),50," ")) n += 1 if n == 10: break

曹曹曹___

#2 Created at ... [Delete] [Delete and Lock User]

n+=1这一行是什么意思啊

n = n+1


  • 1

Reply