程序:
import copy
a=[[1,2],[3,4],5]
b=a
c=copy.copy(a)
d=copy.deepcopy(a)
print('a=',a,'\n'+'b=',b,'\n'+'c=',c,'\n'+'d=',d,'\n')
a.append(6)
print('a=',a,'\n'+'b=',b,'\n'+'c=',c,'\n'+'d=',d,'\n')
a[1].append(7)
print('a=',a,'\n'+'b=',b,'\n'+'c=',c,'\n'+'d=',d,'\n')
输出结果:
a= [[1, 2], [3, 4], 5]
b= [[1, 2], [3, 4], 5]
c= [[1, 2], [3, 4], 5]
d= [[1, 2], [3, 4], 5]
a= [[1, 2], [3, 4], 5, 6]
b= [[1, 2], [3, 4], 5, 6]
c= [[1, 2], [3, 4], 5]
d= [[1, 2], [3, 4], 5]
a= [[1, 2], [3, 4, 7], 5, 6]
b= [[1, 2], [3, 4, 7], 5, 6]
c= [[1, 2], [3, 4, 7], 5]
d= [[1, 2], [3, 4], 5]