>>> import copy
>>> a = 100
>>> b = copy.copy(a)
>>> c = copy.deepcopy(a)
>>> a
100
>>> b
100
>>> c
100
>>> id(a)
1640280256
>>> id(b)
1640280256
>>> id(c)
1640280256
>>> a = [100, 200]
>>> b = copy.copy(a)
>>> c = copy.deepcopy(a)
>>> id(a)
2485240829768
>>> id(b)
2485240849928
>>> id(c)
2485240862728
>>> a.append(300)
>>> a
[100, 200, 300]
>>> b
[100, 200]
>>> c
[100, 200]
>>> a = [100,200]
>>> b = [300,400]
>>> c = (a,b)
>>> d = copy.copy(c)
>>> e = copy.deepcopy(c)
>>> c
([100, 200], [300, 400])
>>> d
([100, 200], [300, 400])
>>> e
([100, 200], [300, 400])
>>> id(c)
2485240664456
>>> id(d)
2485240664456
>>> id(e)
2485240583944
>>> id(c[0])
2485240905928
>>> id(d[0])
2485240905928
>>> id(e[0])
2485240956232
>>> c[0].append(1000)
>>> c
([100, 200, 1000], [300, 400])
>>> d
([100, 200, 1000], [300, 400])
>>> e
([100, 200], [300, 400])
>>> a = [100,200]
>>> b = [300,400]
>>> c = [a,b]
>>> d = copy.copy(c)
>>> e = copy.deepcopy(c)
>>> c
[[100, 200], [300, 400]]
>>> d
[[100, 200], [300, 400]]
>>> e
[[100, 200], [300, 400]]
>>> id(c)
2485240795784
>>> id(d)
2485240808520
>>> id(e)
2485240760712
>>> id(c[0])
2485240784328
>>> id(d[0])
2485240784328
>>> id(e[0])
2485240759176
>>> c
[[100, 200, 1000], [300, 400]]
>>> d
[[100, 200, 1000], [300, 400]]
>>> e
[[100, 200], [300, 400]]
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |