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.

  • 相关阅读:
    double 和 int 同时存在时的运算
    快速排序
    案例:商品放大镜效果
    淘宝flexible.js源码分析
    案例:模态框拖拽
    Web APIs——BOM
    案例:获取URL参数数据
    案例:5秒之后自动跳转页面
    JS中this指针的指向
    按钮:点击发送短信按钮60秒内不能再次点击的功能
  • 原文地址:https://www.cnblogs.com/testfan/p/8082753.html
Copyright © 2011-2022 走看看