python copy模块
来源:互联网 发布:堆排序算法java实现 编辑:程序博客网 时间:2024/05/21 11:34
1. copy.copy 浅拷贝 只拷贝父对象,不会拷贝对象的内部的子对象。
2. copy.deepcopy 深拷贝 拷贝对象及其子对象
输出结果:
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']]
2. copy.deepcopy 深拷贝 拷贝对象及其子对象
一个很好的例子:
import copya = [1, 2, 3, 4, ['a', 'b']] #原始对象b = a #赋值,传对象的引用c = copy.copy(a) #对象拷贝,浅拷贝d = copy.deepcopy(a) #对象拷贝,深拷贝a.append(5) #修改对象aa[4].append('c') #修改对象a中的['a', 'b']数组对象print 'a = ', aprint 'b = ', bprint 'c = ', cprint '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']]
- python模块 - copy模块
- python copy模块
- Python copy模块
- Python的copy模块
- python小模块-----copy 模块
- python模块系列之 - copy
- python中的copy模块理解
- Python模块学习系列(7)----copy模块
- python常用模块介绍之二:copy模块
- [Python模块学习]copy模块,设计模式中的原型模式
- copy 模块
- python中的copy模块(浅复制和深复制)
- [Python]copy模块学习 -- 深拷贝和浅拷贝
- python中的copy模块(浅复制和深复制)
- python中的copy模块(浅复制和深复制)
- Python中使用copy模块实现列表(list)拷贝
- Python中使用copy模块实现列表(list)拷贝
- python copy()
- [面试算法]链表类面试算法解题思路
- Android UI设计技巧
- Software Industry Revolution
- TaintDroid: An Information-Flow Tracking System for Realtime Privacy Monitoring on Smartphones
- 操作系统核心对象与GDI对象
- python copy模块
- MVC razor 中 RenderPartial, RenderAction , Partial , Action 的使用选择
- iOS 6 by Tutorials Chinese Version Now Available!
- 各大企业邮箱发件限制
- 优化Linux内核
- 二极管名称-按功能分
- C语言精确获得消耗时间
- HDU-2444 二分图的判别和最大匹配数。
- 删除集合中重复的数据