python-多重list的拷贝 发表于 2019-09-15 | 分类于 python 单重list的拷贝12345678910a = [1, 2, 3]b = ac = a[:]a.append(4)a[0] = 5print("原数组:", a)print("引用赋值:", b)print("拷贝:", c) 原数组: [5, 2, 3, 4] 引用赋值: [5, 2, 3, 4] 拷贝: [1, 2, 3] 多重list的拷贝1234567891011121314import copya = [[1, 2, 3], [4, 5, 6]]b = ac = copy.copy(a)d = copy.deepcopy(a)a.append(47)a[0][0] = 10print("原数组:", a)print("引用赋值:", b)print("浅拷贝:", c)print("深拷贝:", d) 原数组: [[10, 2, 3], [4, 5, 6], 47] 引用赋值: [[10, 2, 3], [4, 5, 6], 47] 浅拷贝: [[10, 2, 3], [4, 5, 6]] 深拷贝: [[1, 2, 3], [4, 5, 6]]