import copy
# 1 不可变容器
# t1 = (1, 2, 3) # 元组
#
# t1_copy = copy.deepcopy(t1)
#
# print(t1, t1_copy)
# print(id(t1), id(t1_copy))
# 深拷贝 碰到 不可变容器, 直接 复用
# 2 可变容器
# list1 = [1, 2, 3] # 列表
#
# list1_copy = copy.deepcopy(list1)
#
# print(list1, list1_copy)
# print(id(list1), id(list1_copy)) # 不一样 # 1425584520000 1425583776192
# 深拷贝 碰到 可变容器, 开辟新的空间, 将就容器内容 搬过去
# 3 不可变容器 保存 不可变容器
# t1 = (1, 2, 3)
# t2 = (3, 4, 5, 6)
# data = (t1, t2)
# data_copy = copy.deepcopy(data)
#
# print(data, ' ====> ', data_copy)
# print(id(data), ' ====> ', id(data_copy)) # 一样 # 1484746383104 ====> 1484746383104
# print(id(data[0]), ' ====> ', id(data_copy[0])) # 一样 # 1484746082432 ====> 1484746082432
# 深拷贝 碰到 不可变容器, 直接 复用
# 4 不可变容器 保存 可变容器
# list1 = [1, 2, 3]
# list2 = [4, 5, 6, 7]
# data = (list1, list2)
#
# data_copy = copy.deepcopy(data)
#
# print(data, ' ====> ', data_copy)
# print(id(data), ' ====> ', id(data_copy)) # 不一样 # 2814101009408 ====> 2814100755264
# print(id(data[0]), ' ====> ', id(data_copy[0])) # 不一样 # 2814144248128 ====> 2814143373888
# 深拷贝 碰到 不可变容器, 不一定
# 5 可变容器 保存 不可变容器
# t1 = (1, 2, 3)
# t2 = (3, 4, 5, 6)
#
# data = [t1, t2]
#
# data_copy = copy.deepcopy(data)
#
# print(data, ' ====> ', data_copy)
# print(id(data), ' ====> ', id(data_copy)) # 不一样 # 3151279393728 ====> 3151278711488
# print(id(data[0]), ' ====> ', id(data_copy[0])) # 一样 # 2041825675392 ====> 2041825675392
# 6 可变容器 保存 可变容器
# list1 = [1, 2, 3]
# list2 = [4, 5, 6, 7]
#
# data = [list1, list2]
#
# data_copy = copy.deepcopy(data)
#
# print(data, ' ====> ', data_copy)
# print(id(data), ' ====> ', id(data_copy)) # 不一样 # 2087020412352 ====> 2087020400320
# print(id(data[0]), ' ====> ', id(data_copy[0])) # 不一样 # 2087021283904 ====> 2087020400576
# 题目1: 判断b的结果
# a = [1, 3, 5, [7, 9], 10]
#
# b = copy.deepcopy(a)
#
# a[3][0] = 1000
#
# print(b) # A
# A [1, 3, 5, [7, 9], 10]
# B [1, 3, 5, [1000, 9], 10]
# 题目2: 判断b的结果
# a = (1, 3, 5, (7, 9), 10)
#
# b = copy.deepcopy(a)
#
# a[1] = 1000
#
# print(b)
# A [1, 3, 5, [7, 9], 10]
# B [1, 3, 5, [1000, 9], 10]
# C 报错
上面为深拷贝,下面运行浅拷贝
import copy
# 1 不可变容器
# t1 = (1, 2, 3) # 元组
#
# t1_copy = copy.copy(t1)
#
# print(t1, t1_copy)
# print(id(t1), id(t1_copy))
# 浅拷贝 碰到 不可变容器, 直接 复用
# 2 可变容器
# list1 = [1, 2, 3] # 列表
#
# list1_copy = copy.copy(list1)
#
# print(list1, list1_copy)
# print(id(list1), id(list1_copy))
# 浅拷贝 碰到 可变容器, 开辟新的空间, 将就容器内容 直接 搬过去
# 3 不可变容器 保存 不可变容器
# t1 = (1, 2, 3)
# t2 = (3, 4, 5, 6)
# data = (t1, t2)
# data_copy = copy.copy(data)
#
# print(data, ' ====> ', data_copy)
# print(id(data), ' ====> ', id(data_copy)) # 2068501028352 ====> 2068501028352
# print(id(data[0]), ' ====> ', id(data_copy[0])) # 2278274516864 ====> 2278274516864
# 浅拷贝 碰到 不可变容器, 直接 复用
# 4 不可变容器 保存 可变容器
# list1 = [1, 2, 3]
# list2 = [4, 5, 6, 7]
# data = (list1, list2)
#
# data_copy = copy.copy(data)
#
# print(data, ' ====> ', data_copy)
# print(id(data), ' ====> ', id(data_copy)) # 一样 # 2830287221824 ====> 2830287221824
# print(id(data[0]), ' ====> ', id(data_copy[0])) # 一样 # 2830330399360 ====> 2830330399360
# 浅拷贝 碰到 不可变容器, 直接 复用
# 5 可变容器 保存 不可变容器
# t1 = (1, 2, 3)
# t2 = (3, 4, 5, 6)
#
# data = [t1, t2]
#
# data_copy = copy.copy(data)
#
# print(data, ' ====> ', data_copy)
# print(id(data), ' ====> ', id(data_copy)) # 不一样 # 2191729855296 ====> 2191729041728
# print(id(data[0]), ' ====> ', id(data_copy[0])) # 一样 # 2191688091712 ====> 2191688091712
# 6 可变容器 保存 可变容器
# list1 = [1, 2, 3]
# list2 = [4, 5, 6, 7]
#
# data = [list1, list2]
#
# data_copy = copy.copy(data)
#
# print(data, ' ====> ', data_copy)
# print(id(data), ' ====> ', id(data_copy)) # 不一样 # 2494044782336 ====> 2494044778560
# print(id(data[0]), ' ====> ', id(data_copy[0])) # 一样 # 2494045653568 ====> 2494045653568
# 浅拷贝 碰到 可变容器, 开辟新的空间, 将旧容器内容 直接 搬过去
# 题目1: 判断b的结果
# a = [1, 3, 5, [7, 9], 10]
#
# b = copy.copy(a)
#
# a[3][0] = 1000
#
# print(b)
# A [1, 3, 5, [7, 9], 10]
# B [1, 3, 5, [1000, 9], 10]
# 题目2: 判断b的结果
# a = (1, 3, 5, [7, 9], 10)
#
# b = copy.copy(a)
#
# a[3][0] = 1000
#
# print(b)
# A [1, 3, 5, [7, 9], 10]
# B [1, 3, 5, [1000, 9], 10]
# 题目3: 判断b的结果
# a = (1, 3, 5, (7, 9), 10)
#
# b = copy.copy(a)
#
# a[3][0] = 1000
#
# print(b)
# A [1, 3, 5, [7, 9], 10]
# B [1, 3, 5, [1000, 9], 10]
# C 报错