n1 = [1,2,3,4,5]
n2 = n1
n3 = n1[:]
n1[0] = 33
n3[1] = 999
print(n1)
print(n2)
print(n3)
正确答案是:
n1 = [33,2,3,4,5]
n2=[33,2,3,4,5]
n3 = [1,999,3,4,5]
解释: n2=n1赋值的时候n2和n1指向同一块地址,n1改变了,n2也跟着改变
n3 = n1[:]切片操作,又开辟了新的内存空间,指向的是新的,所以n1变化,n3不变
n1 = [1,2,3,4,5]
n2 = n1
n3 = n1[:]
n1[0] = 33
n3[1] = 999
print(n1)
print(n2)
print(n3)
正确答案是:
n1 = [33,2,3,4,5]
n2=[33,2,3,4,5]
n3 = [1,999,3,4,5]
解释: n2=n1赋值的时候n2和n1指向同一块地址,n1改变了,n2也跟着改变
n3 = n1[:]切片操作,又开辟了新的内存空间,指向的是新的,所以n1变化,n3不变