当前位置:网站首页>Difference between shallow copy and deep copy
Difference between shallow copy and deep copy
2022-07-28 06:14:00 【Ke Yulong】
The difference between deep copy and shallow copy :
1、 The shallow copy just copies the reference address of the object , Two objects point to the same memory address , So modify any of these values , Another value will change with it , This is a shallow copy ( example :assign())
2、 Deep copy is to copy objects and values , Two objects modify any of the values and the other does not change , This is the deep copy .
The simple understanding is : That is the assumption. B Copy the A, When modifying A when , see B Will it change , If B And then it changed , It means it's a shallow copy , Short hand , If B It hasn't changed , That's deep copy . If the element in the copied object has only value , There is no reference , There is no difference between a deep copy and a shallow copy , Will copy a copy of the original object , Generate a new object , Changing the value in the new object will not affect the original object , The new object is completely separated from the original object .
————————————————
Code implementation
import copy
a = [1,2,3,4,5,['a','b','c']]
b = a
c = copy.copy(a)
d = copy.deepcopy(a)
a.append(5)
a[5].append('d')
print('b',b) # [1,2,3,4,5,['a','b','c','d'],5]
print('c',c) # [1,2,3,4,5,['a','b','c','d']]
print('d',d)# [1,2,3,4,5,['a','b','c']]

边栏推荐
- matplotlib数据可视化
- Small program development solves the anxiety of retail industry
- 神经网络学习
- Various programming languages decimal | time | Base64 and other operations of the quick look-up table
- Record the problems encountered in online capacity expansion server nochange: partition 1 is size 419428319. It cannot be grown
- What are the general wechat applet development languages?
- 四、模型优化器与推理引擎
- Deep learning (incremental learning) -- iccv2021:ss-il: separated softmax for incremental learning
- 自动定时备份远程mysql脚本
- Construction of redis master-slave architecture
猜你喜欢

Four perspectives to teach you to choose applet development tools?

Reinforcement learning - Strategic Learning

强化学习——价值学习中的DQN

深度学习(自监督:MoCo v2)——Improved Baselines with Momentum Contrastive Learning

强化学习——多智能体强化学习

深度学习(增量学习)——(ICCV)Striking a Balance between Stability and Plasticity for Class-Incremental Learning

Latex入门

一、语音合成与自回归模型

强化学习——连续控制

Solution to the crash after setting up a cluster
随机推荐
Bert的使用方法
Cluster operation management system, to answer questions about the process
What are the general wechat applet development languages?
Dataset类分批加载数据集
Which enterprises are suitable for small program production and small program development?
Reinforcement learning - Basic Concepts
Tf.keras build neural network function expansion
无约束低分辨率人脸识别综述三:同质低分辨率人脸识别方法
matplotlib数据可视化
Classification of iris based on Neural Network
二、OpenVINO简述与构建流程
深度学习(增量学习)——(ICCV)Striking a Balance between Stability and Plasticity for Class-Incremental Learning
What are the advantages of small program development system? Why choose it?
Four perspectives to teach you to choose applet development tools?
flutter webivew input唤起相机相册
机器学习之聚类
Self attention learning notes
Digital collections become a new hot spot in tourism industry
NLP中常用的utils
Utils commonly used in NLP