zoukankan      html  css  js  c++  java
  • 浅拷贝与深拷贝

    python的copy模块中分为copy和deepcopy函数;

    下面是python的官方解释:

    copy.copy(x)

    Return a shallow copy of x.

    copy.deepcopy(x)

    Return a deep copy of x.

    The difference between shallow and deep copying is only relevant for compound objects (objects that contain other objects, like lists or class instances):

    • A shallow copy constructs a new compound object and then (to the extent possible) inserts references into it to the objects found in the original.
    • A deep copy constructs a new compound object and then, recursively, inserts copies into it of the objects found in the original.

    Two problems often exist with deep copy operations that don’t exist with shallow copy operations:

    • Recursive objects (compound objects that, directly or indirectly, contain a reference to themselves) may cause a recursive loop.
    • Because deep copy copies everything it may copy too much, e.g., even administrative data structures that should be shared even between copies.

    The deepcopy() function avoids these problems by:

    • keeping a “memo” dictionary of objects already copied during the current copying pass; and
    • letting user-defined classes override the copying operation or the set of components copied.

    This module does not copy types like module, method, stack trace, stack frame, file, socket, window, array, or any similar types. It does “copy” functions and classes (shallow and deeply), by returning the original object unchanged; this is compatible with the way these are treated by the pickle module.

  • 相关阅读:
    经典SQL例题
    truncate,delete,drop的异同点
    scp 在不同主机之间数据传输
    自定义标签库
    servlet 学习
    HTTP协议 学习
    Tomcat服务器的数字证书 HTTPS 连接!
    JSP开发 路径问题汇总
    java 文件上传 下载 总结
    myeclipse 出现换行符和空格符 解决方案 换行出现乱码
  • 原文地址:https://www.cnblogs.com/testfan/p/8082753.html
Copyright © 2011-2022 走看看