Python 深拷贝和浅拷贝
Python中,对象的赋值,拷贝(深/浅拷贝)之间是有差异的,如果使用的时候不注意,就可能产生意外的结果。 下面本文就通过简单的例子介绍一下这些概念之间的差别。 对象赋值 直接看一段代码: will=["Will",28,["Python","C#","JavaScript"]] wilber=will print id(will) print will print [id(x) for x in will] print id(wilber) print wilber print [id(x) for x in wilber] print '*****************' will[0]='Wilber' will[2].append("CSS") print id(will) print will print [id(x) for x in will] print id(wilber) print wilber print [id(x) for x in wilber] 结果: 36589768 ['Will', 28, ['Python', 'C#', 'JavaScript']] [36564144L, 30898752L, 36589704L] 36589768 ['Will', 28, ['Python', 'C#', 'JavaScript']]