浅拷贝
name1 = ["hello","me"]
name2 = name1.copy()
name1[1] = 'you'
print(name1)
print(name2)
name1 = ["hello","me"]
name2 = name1.copy()
name2[1] = 'you'
print(name1)
print(name2)
name1 = ["hello","me",["you","way"]]
name2 = name1.copy()
name1[2][1] = 'you'
name1[0] = 'word'
print(name1)
print(name2)
浅拷贝的三种方式
list1 = [1,3,5,7]
p1 = copy.copy(list1)
p2 = list1[:]
p3 = list[list1]
浅拷贝的用途:创建联合账号
深拷贝
import copy
name1 = ["hello","me",["you","way"]]
name2 = copy.deepcopy(name1)
name1[2][1] = 'you'
name1[0] = 'word'
print(name1)
print(name2)