代码
import copy
a = [[1, 2, 3], [4, 5, 6]]
b = a
c = copy.copy(a)
d = copy.deepcopy(a)
print('a-id:', id(a))
print('b-id:',id(b))
print('c-id:',id(c))
print('d-id:',id(d))
a.append(15)
a[1][2] = 10
print('processed...')
print(a)
print(b)
print(c)
print(d)
结果
a-id: 108075528
b-id: 108075528
c-id: 110917832
d-id: 111121800
processed...
[[1, 2, 3], [4, 5, 10], 15]
[[1, 2, 3], [4, 5, 10], 15]
[[1, 2, 3], [4, 5, 10]]
[[1, 2, 3], [4, 5, 6]]
网友评论