当前位置:网站首页>Deep copy and shallow copy [interview question 3]
Deep copy and shallow copy [interview question 3]
2022-07-05 18:25:00 【CrazyManhhh】
The difference between deep copy and shallow copy
Shallow copy , To reallocate a piece of memory , Create a new object , But the element inside is the reference of each sub object in the original object . because l2 The address of the previous object is used , So when [2,3,4] When adding data ,l2 The data of has also changed
import copy
def cal(l):
l[-1].append(6)
l.append(5)
return l
l = [1,2,[2,3,4]]
l2 = l.copy()
print(cal(l))
print(l2)
# Output results
#[1, 2, [2, 3, 4, 6], 5]
#[1, 2, [2, 3, 4, 6]]
Deep copy , To reallocate a piece of memory , Create a new object , And the elements in the original object , In a recursive way , Copy to the new object by creating a new sub object . therefore , The new object has nothing to do with the original object .
边栏推荐
- Login and connect CDB and PDB
- About statistical power
- 兄弟组件进行传值(显示有先后顺序)
- Share: ZTE Yuanhang 30 Pro root unlock BL magick ZTE 7532n 8040n 9041n brush mask original brush package root method Download
- jdbc读大量数据导致内存溢出
- Isprs2022 / Cloud Detection: Cloud Detection with Boundary nets Boundary Networks Based Cloud Detection
- 开户注册股票炒股安全吗?有没有风险的?靠谱吗?
- MATLAB中print函数使用
- FCN: Fully Convolutional Networks for Semantic Segmentation
- Let more young people from Hong Kong and Macao know about Nansha's characteristic cultural and creative products! "Nansha kylin" officially appeared
猜你喜欢
FCN: Fully Convolutional Networks for Semantic Segmentation
Star ring technology data security management platform defender heavy release
@Extension, @spi annotation principle
【HCIA-cloud】【1】云计算的定义、什么是云计算、云计算的架构与技术说明、华为云计算产品、华为内存DDR配置工具说明
Introduction to the development function of Hanlin Youshang system of Hansheng Youpin app
如何获取飞机穿过雷达两端的坐标
vulnhub之darkhole_2
最大人工岛[如何让一个连通分量的所有节点都记录总节点数?+给连通分量编号]
瞅一瞅JUC提供的限流工具Semaphore
The 11th China cloud computing standards and Applications Conference | China cloud data has become the deputy leader unit of the cloud migration special group of the cloud computing standards working
随机推荐
[paddlepaddle] paddedetection face recognition custom data set
LeetCode 6111. 螺旋矩阵 IV
Le cours d'apprentissage de la machine 2022 de l'équipe Wunda arrive.
The 11th China cloud computing standards and Applications Conference | cloud computing national standards and white paper series release, and Huayun data fully participated in the preparation
破解湖+仓混合架构顽疾,星环科技推出自主可控云原生湖仓一体平台
Electron installation problems
Is it safe to open an account, register and dig money? Is there any risk? Is it reliable?
使用JMeter录制脚本并调试
图像分类,看我就够啦!
[use electron to develop desktop on youqilin]
How to solve the error "press any to exit" when deploying multiple easycvr on one server?
Trust counts the number of occurrences of words in the file
The origin of PTS, DTS and duration of audio and video packages
@Extension、@SPI注解原理
vulnhub之darkhole_2
LeetCode 6109. Number of people who know the secret
Logical words in Articles
Record a case of using WinDbg to analyze memory "leakage"
Gimp 2.10 tutorial "suggestions collection"
Notes on common management commands of openshift