当前位置:网站首页>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']]

边栏推荐
猜你喜欢

将项目部署到GPU上,并且运行

D2SC-GAN:基于双深浅通道生成对抗网络的课堂场景低分辨率人脸识别

Building neural network based on tensorflow

《Distilling the Knowledge in a Neural Network》知识蒸馏论文解读

Reinforcement learning - continuous control

Deep learning (self supervision: CPC V2) -- data efficient image recognition with contractual predictive coding

Reinforcement learning - Multi-Agent Reinforcement Learning

Word2vec+ regression model to achieve classification tasks

Knowledge point 21 generic

What are the detailed steps of wechat applet development?
随机推荐
matplotlib数据可视化
深度学习(自监督:MoCo V3):An Empirical Study of Training Self-Supervised Vision Transformers
Word2vec+ regression model to achieve classification tasks
Deep learning - metaformer is actually what you need for vision
Bert的使用方法
深度学习(自监督:SimSiam)——Exploring Simple Siamese Representation Learning
2: Why read write separation
深度学习(增量学习)——(ICCV)Striking a Balance between Stability and Plasticity for Class-Incremental Learning
将项目部署到GPU上,并且运行
Which enterprises are suitable for small program production and small program development?
Nlp项目实战自定义模板框架
强化学习——连续控制
Using neural network to predict the weather
Solution to the crash after setting up a cluster
Utils commonly used in NLP
Sqlalchemy usage related
自动定时备份远程mysql脚本
深度学习——Pay Attention to MLPs
What about the app store on wechat?
Digital collections become a new hot spot in tourism industry