6.in深浅拷贝图示

深浅拷贝

import copy

lis1 = [1,2,[1,2,3]]
lis2 = lis1
lis3 = copy.copy(lis1)
lis4 = copy.deepcopy(lis1)

print(id(lis1))
print(id(lis2))
print(id(lis3))
print(id(lis4))
print('-'*60)

print(id(lis1[0]))
print(id(lis2[0]))
print(id(lis3[0]))
print(id(lis4[0]))
print('-'*60)

print(id(lis1[1]))
print(id(lis2[1]))
print(id(lis3[1]))
print(id(lis4[1]))
print('-'*60)

print(id(lis1[2]))
print(id(lis2[2]))
print(id(lis3[2]))
print(id(lis4[2]))
print('-'*60)

print(id(lis1[2][0]))
print(id(lis2[2][0]))
print(id(lis3[2][0]))
print(id(lis4[2][0]))
print('-'*60)

print(id(lis1[2][1]))
print(id(lis2[2][1]))
print(id(lis3[2][1]))
print(id(lis4[2][1]))
print('-'*60)

print(id(lis1[2][2]))
print(id(lis2[2][2]))
print(id(lis3[2][2]))
print(id(lis4[2][2]))
15877384
15877384
15879424
52865224
------------------------------------------------------------
1467140224
1467140224
1467140224
1467140224
------------------------------------------------------------
1467140240
1467140240
1467140240
1467140240
------------------------------------------------------------
15949992
15949992
15949992
52865424
------------------------------------------------------------
1467140224
1467140224
1467140224
1467140224
------------------------------------------------------------
1467140240
1467140240
1467140240
1467140240
------------------------------------------------------------
1467140256
1467140256
1467140256
1467140256

posted @ 2019-05-09 16:14  yellowcloud  阅读(149)  评论(0编辑  收藏  举报
回顶部