python列表拷贝

    

1.变量的赋值,指示地址的指向

例:

import copy

names  =  ["Roger","Tom",[1,2,3],"Lili"]

names2 = names

names[1] = "Smith"

names[2][0] = 9

print(names)

print(names2)

 

2.列表的copy(),是潜拷贝

names2 = names.copy()

3.copy.copy(names),是潜拷贝,与2效果相同

names2 = copy.copy(names)

4.切片

names2=names[:]#是潜拷贝,与2,3效果相同

5.list

names2=list(names)#是潜拷贝,与2,3,4效果相同

 

6.copy.deepcopy(names),是深拷贝

names2 = copy.deepcopy(am)

 

posted @ 2018-05-23 08:38  强巴  阅读(123)  评论(0编辑  收藏  举报