Discuss / Python / 为什么第二行不会是[1,1,1] 啊

为什么第二行不会是[1,1,1] 啊

Topic source

蘭__吾凡

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

def triangles():

    g = [1]

    while True:

        yield g

        g = [1] + [g[x - 1] + g[x] for x in range(1, len(g))] + [1]

Defias-迪

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

 有点不明白,当g=[1]时  len(g)==1   range(1, len(g))是个空列表,x取不到值  g[x]却不报错???


  • 1

Reply