不可变对象
#coding:utf-8
s3 = [1,'hello',[1,2]]
s4 = s3[:]
s5 = list(s3)
print id(3),id(4),id(5)
'浅拷贝后更新不可变对象的值'
s3[0] = 0
print s3
print s4
print s5
输出
44333256 44333244 44333232
[0, 'hello', [1, 2]]
[1, 'hello', [1, 2]]
[1, 'hello', [1, 2]]
可变对象
#浅拷贝后更新可变对象的值
s5[2][1]='keek'
prints3
prints4
print s5
输出
[0, 'hello', [1, 'keek']]
[1, 'hello', [1, 'keek']]
[1, 'hello', [1, 'keek']]
s2 = s1[:]
s2 = list(s1)
import copy
s2 = copy.copy(s1)#浅拷贝
s2 = copy.deepcopy(s1)