Python元组应用copy模块的深拷贝和浅拷贝思路整理-1

import copy
a=(11,22)
a1=list(a)
a2=tuple(a1)
A= copy.copy(a)
A_=copy.deepcopy(a)
print(a,"a的id:",id(a))
print(a1,"a1的id:",id(a1))
print(a2,"a2的id:",id(a2))
print(A,"A copy.copy的id:",id(A))# id 不变
print(A_,"A_ copy.copy的id:",id(A_)) #id 不变

print("-------------修改后-----------------")
a1.append(33)
a3=tuple(a1)
print(a,"a的id:",id(a))
print(a1,"a1的id:",id(a1))
print(a3,"a2的id:",id(a3))

Python元组应用copy模块的深拷贝和浅拷贝思路整理-1_第1张图片对于元组,无论是深拷贝还是浅拷贝,都只是复制了指向,id都不会变

你可能感兴趣的:(Python)