Python里的拷贝=====》很容易错误的
2016-08-30 22:17
239 查看
不能直接用 = 复制:
import copy a = [1, 2, 3, 4, ['a', 'b']] #原始对象 b = a #赋值,传对象的引用 c = copy.copy(a) #对象拷贝,浅拷贝 d = copy.deepcopy(a) #对象拷贝,深拷贝 a.append(5) #修改对象a a[4].append('c') #修改对象a中的['a', 'b']数组对象 print 'a = ', a print 'b = ', b print 'c = ', c print 'd = ', d 输出结果: a = [1, 2, 3, 4, ['a', 'b', 'c'], 5] b = [1, 2, 3, 4, ['a', 'b', 'c'], 5] c = [1, 2, 3, 4, ['a', 'b', 'c']] d = [1, 2, 3, 4, ['a', 'b']]
dd
相关文章推荐
- python错误TypeError: 'module' object is not callable 的解决方法
- Python指南--错误和异常
- 【转载老猫】汇总新手SEO很容易犯的错误
- Python 2.7 Tutorial —— 错误和异常
- python-rrdtool创建rrd文件的TypeError: argument 0 must be string 错误
- Python 2.7 Tutorial —— 错误和异常
- 学学python(2):错误和异常
- weblogic9中配置web服务遇到的很普通很容易犯的错误
- python错误:TypeError: 'str' object is not callable
- Python指南--错误和异常
- Windows下解决 MySQL-python-1.2.3b1 的安装编译错误
- python 模块导入时的错误
- python 错误的原因 token Error: EOF in multi-line statement
- 解决 MySQL-python-1.2.3b1 的安装错误
- java 中一个很容易忽略的多线程错误!
- 内嵌Python import时undefined symbol错误及解决
- 怎样把Python嵌入Windows应用中(本人译文,不当或错误之处请指正)
- python eric 中的错误:The file could not be opened.
- python maxlength错误
- python try语句如何打印错误行