l1 = [1, [2, 3], 4]
l2 = [1, [2, 3], 4] # 新建对象l2,虽然看起来和l1一样,但其实是新的对象,二者互不影响没有任何关系(开辟新地址)
l3 = l1 # 对象的赋值,l3与l1 一模一样(不开辟新地址)
l4 = copy.copy(l1) # l4只拷贝l1的父对象,产生新对象,l1父级元素更改不影响l4,子元素更改l4跟着变更(开辟新地址)
l5 = copy.deepcopy(l1) # l5彻底拷贝l1,产生互不影响的新对象,l1的任何变更均不影响l5(开辟新地址)
print l1 # [1, [2, 3], 4]
print l2 # [1, [2, 3], 4]
print l3 # [1, [2, 3], 4]
print l4 # [1, [2, 3], 4]
print l5 # [1, [2, 3], 4]
print 'l1-id:', id(l1) # 7664
print 'l2-id:', id(l2) # 6440
print 'l3-id:', id(l3) # 7664
print 'l4-id:', id(l4) # 8168
print 'l5-id:', id(l5) # 7880
print 'l1==l2:', l1 == l2 # true
print 'l1==l3:', l1 == l3 # true
print 'l1==l4:', l1 == l4 # true
print 'l1==l5:', l1 == l5 # true
print 'l1 is l2:', l1 is l2 # false
print 'l1 is l3:', l1 is l3 # true
print 'l1 is l4:', l1 is l4 # false
print 'l1 is l5:', l1 is l5 # false
print '--------------原始值改变后----------------'
l1[1][0] = 0
l1[0] = 0
l4[1][1] = 'a'
print l1 # [0, [0, 'a'], 4]
print l2 # [1, [2, 3], 4]
print l3 # [0, [0, 'a'], 4]
print l4 # [1, [0, 'a'], 4]
print l5 # [1, [2, 3], 4]
print 'l1-id:', id(l1) # 7664
print 'l2-id:', id(l2) # 6440
print 'l3-id:', id(l3) # 7664
print 'l4-id:', id(l4) # 8168
print 'l5-id:', id(l5) # 7880
print 'l1==l2:', l1 == l2 # false
print 'l1==l3:', l1 == l3 # true
print 'l1==l4:', l1 == l4 # false
print 'l1==l5:', l1 == l5 # false
print 'l1 is l2:', l1 is l2 # false
print 'l1 is l3:', l1 is l3 # true
print 'l1 is l4:', l1 is l4 # false
print 'l1 is l5:', l1 is l5 # false