#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""
Created by liaoyangyang1 on 2018/8/23 下午1:41.
"""
# 简单来说,就是copy出来的对象cp1,如果demo改了他会跟着改。但是deepcopy 出来的 cp2还是原来的值
import copy
demo2 = demo = [1, 2, [3, 4]] #origin 里#边有三个元素:1, 2,[3, 4]
cp1 = copy.copy(demo)
cp2 = copy.deepcopy(demo)
print(id(demo))
print(id(cp1))
print(id(cp2))
print(cp1)
print(cp2)
print(cp1 == cp2)
print(cp1 is cp2 )
print(cp1 is demo )
print(cp2 is demo )
print(demo2 is demo )
print('='*100)
#cp1 和 co2 看上去相同,但#已不再是同一个object
#把demo内的子list [3, 4] 改掉了#一个元素,观察到 cp1 和 #cp2的变化如下所示:
demo2[2][0] = "hi"
demo =[1, 2, ['hi', 4]]
print(cp1)
print(cp2)