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.

  • 相关阅读:
    selenium+java利用AutoIT实现文件上传
    java+selenium自动化遇到confirm弹窗,出现NoAlertPresentException: no alert open
    Appium遇到问题:
    selenium2+java切换窗口
    nodejs
    连续12天的加班工作总结-根据客户选择来生成后续表单页面
    最近三家公司面试的总结吐槽及一点点总结
    nodeJs-autoMerge
    nodeJs-autoBulid
    Angular 学习笔记——ng-Resource1
  • 原文地址:https://www.cnblogs.com/testfan/p/8082753.html
Copyright © 2011-2022 走看看