定义:
lista = [2,[4,5]]
5种拷贝方式:
1.listb = lista[:]
2.listb = list(lista)
3.listb = [i for i in lista]
4.import copy; listb = copy.copy(lista)
5.
import copy; listb = copy.deepcopy(lista)
拷贝后续操作:
listb[1].append(9)
print lista, listb
五种拷贝方式后续操作的结果:
1.
[2, [4, 5, 9]] [2, [4, 5, 9]]
2. [2, [4, 5, 9]] [2, [4, 5, 9]]
3. [2, [4, 5, 9]] [2, [4, 5, 9]]
4. [2, [4, 5, 9]] [2, [4, 5, 9]]
5. [2, [4, 5]] [2, [4, 5, 9]]
阅读(1052) | 评论(1) | 转发(0) |