Python 浅拷贝和深拷贝

Python 浅拷贝和深拷贝
import  copy
a
= [ 1 , 2 , 3 , 4 ,[ ' a ' , ' b ' ]]
b
= a
c
= copy.copy(a)
d
= copy.deepcopy(a)

a.append(
5 )
a[
4 ].append( ' c ' )

print   ' a= ' ,a
print   ' b= ' ,b
print   ' c= ' ,c
print   ' d= ' ,d

输出
a= [1, 2, 3, 4, ['a', 'b', 'c'], 5]
b= [1, 2, 3, 4, ['a', 'b', 'c'], 5]
c= [1, 2, 3, 4, ['a', 'b', 'c']]
d= [1, 2, 3, 4, ['a', 'b']]


你可能感兴趣的:(Python 浅拷贝和深拷贝)