Discuss / Python / 作业及疑问

作业及疑问

Topic source

代代树

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

作业

def triangles():
    L=[1]
    T=L
    a=0
    while True:
        i=1
        a+=1
        T=L.copy()
        yield L
        while i<a:
            L[i]=T[i-1]+T[i]
            i+=1
        L.append(1)

n = 0
for t in triangles():
    print(t)
    n = n + 1
    if n == 10:
        break

有个疑问,我一开始是用T=L,这样赋值的,一直报错,后来改成了T=L.copy()才对了,请问 T=L,T=L.copy()是什么差异呢?


  • 1

Reply