==copy 模块==

``copy`` 模块包含两个函数, 用来拷贝对象, 如 [Example 1-64 #eg-1-64] 所示. 

``copy(object) => object`` 创建给定对象的 "浅/浅层(shallow)" 拷贝(copy). 这里
"浅/浅层(shallow)" 的意思是复制对象本身, 但当对象是一个容器 (container) 时,
它的成员仍然指向原来的成员对象. ====Example 1-64. 使用 copy 模块复制对象====[eg-1-64] ```
File: copy-example-1.py import copy a = [[1],[2],[3]]
b = copy.copy(a) print "before", "=>"
print a
print b # modify original
a[0][0] = 0
a[1] = None print "after", "=>"
print a
print b *B*before =>
[[1], [2], [3]]
[[1], [2], [3]]
after =>
[[0], None, [3]]
[[0], [2], [3]]*b*
``` 你也可以使用[:]语句 (完整切片) 来对列表进行浅层复制, 也可以使用 ``copy`` 方法复制字典. 相反地, ``deepcopy(object) => object`` 创建一个对象的深层拷贝(deepcopy),
如 [Example 1-65 #eg-1-65] 所示, 当对象为一个容器时, 所有的成员都被递归地复制了。 ====Example 1-65. 使用 copy 模块复制集合(Collections)====[eg-1-65] ```
File: copy-example-2.py import copy a = [[1],[2],[3]]
b = copy.deepcopy(a) print "before", "=>"
print a
print b # modify original
a[0][0] = 0
a[1] = None print "after", "=>"
print a
print b *B*before =>
[[1], [2], [3]]
[[1], [2], [3]]
after =>
[[0], None, [3]]
[[1], [2], [3]]*b*
```

python标准库介绍——9 copy模块详解的更多相关文章

  1. python标准库介绍——27 random 模块详解

    ==random 模块== "Anyone who considers arithmetical methods of producing random digits is, of cour ...

  2. python标准库介绍——12 time 模块详解

    ==time 模块== ``time`` 模块提供了一些处理日期和一天内时间的函数. 它是建立在 C 运行时库的简单封装. 给定的日期和时间可以被表示为浮点型(从参考时间, 通常是 1970.1.1 ...

  3. python标准库介绍——10 sys 模块详解

    ==sys 模块== ``sys`` 模块提供了许多函数和变量来处理 Python 运行时环境的不同部分. === 处理命令行参数=== 在解释器启动后, ``argv`` 列表包含了传递给脚本的所有 ...

  4. python标准库介绍——30 code 模块详解

    ==code 模块== ``code`` 模块提供了一些用于模拟标准交互解释器行为的函数. ``compile_command`` 与内建 ``compile`` 函数行为相似, 但它会通过测试来保证 ...

  5. python标准库介绍——8 operator 模块详解

    ==operator 模块== ``operator`` 模块为 Python 提供了一个 "功能性" 的标准操作符接口. 当使用 ``map`` 以及 ``filter`` 一类 ...

  6. python标准库介绍——36 popen2 模块详解

    ==popen2 模块== ``popen2`` 模块允许你执行外部命令, 并通过流来分别访问它的 ``stdin`` 和 ``stdout`` ( 可能还有 ``stderr`` ). 在 pyth ...

  7. python标准库介绍——35 pipes 模块详解

    ==pipes 模块== (只用于 Unix) ``pipes`` 模块提供了 "转换管道 (conversion pipelines)" 的支持. 你可以创建包含许多外部工具调用 ...

  8. python标准库介绍——28 md5 模块详解

    ==md5 模块== ``md5`` (Message-Digest Algorithm 5)模块用于计算信息密文(信息摘要). ``md5`` 算法计算一个强壮的128位密文. 这意味着如果两个字符 ...

  9. python标准库介绍——23 UserString 模块详解

    ==UserString 模块== (2.0 新增) ``UserString`` 模块包含两个类, //UserString// 和 //MutableString// . 前者是对标准字符串类型的 ...

随机推荐

  1. [转载]Elasticsearch索引重建(Rebuild)

    From:http://blog.csdn.net/changong28/article/details/38491185 索引重建(Rebuild) 索引创建后,你可以在索引当中添加新的类型,在类型 ...

  2. 【转】php里面也可以使用协程

    原文链接:http://blog.51cto.com/chinalx1/2089327 http://nikic.github.io/2012/12/22/Cooperative-multitaski ...

  3. SecureRandom-随机数的生成

    随机数:算法+种子 随机数据不随机 学习了:https://www.cnblogs.com/deng-cc/p/8064481.html StringBuffer buffer = new Strin ...

  4. Angular报错

    报错: Module 'App' is not available! You either misspelled the module name or forgot to load it. If re ...

  5. Mac Finder中如何复制当前完整路径

    1.拖到命令行 2.在Finder中command+i 会弹出详细信息,然后[位置]处进行 copy 3.利用Automator,添加一个服务的快捷键. 转自:http://q.cnblogs.com ...

  6. [Javascript]1. Improve you speed! Loop optimaztion

    /** Improve you loop code */ var treasureChest = { goldCoins: 10000, magicalItem : "Crown of Sp ...

  7. mac 下vim 配置文件

    " Configuration file for vim set modelines=0 " CVE-2007-2438 " Normally we use vim-ex ...

  8. Vim使用进阶

    作为一个使用vim挺长时间的人,现在来写这篇东西确实是尴尬的,就像很多大神们说的,vim是世界上最好用的编辑器,没有之一.然后前两天又重新看了看vim的那些功能和使用方法,更觉得这么长时间使用vim却 ...

  9. SCSS 实用知识汇总

    1.变量声明 $nav-color: #F90; nav { //$width 变量的作用域仅限于{}内 $width: 100px; width: $width; color: $nav-color ...

  10. LeetCode 37 Count and Say

    The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221 ...