浅拷贝
浅拷贝:拷贝对象,但不拷贝子对象的内容,只是拷贝子对象的引用
def testCopy():"""测试浅拷贝"""a = [10, 20, [5, 6]]b = copy.copy(a)print("a的值为{}".format(a))print("b的值为{}".format(b))"""浅拷贝"""b.append(30)b[2].append(7)print("浅拷贝后,修改b.....")print("a的值为{}".format(a))print("b的值为{}".format(b))if __name__ == '__main__':testCopy()
深拷贝
def testDeepCopy():"""测试深拷贝"""a = [10, 20, [5, 6]]b=copy.deepcopy(a)print("a的值为{}".format(a))print("b的值为{}".format(b))b.append(30)b[2].append(7)print("深拷贝后,修改b的值....")print("a的值为{}".format(a))print("b的值为{}".format(b))if __name__ == '__main__':testDeepCopy()