当前位置:网站首页>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 .
边栏推荐
- How can cluster deployment solve the needs of massive video access and large concurrency?
- Multithreading (I) processes and threads
- Cronab log: how to record the output of my cron script
- 含重复元素取不重复子集[如何取子集?如何去重?]
- Nanjing University: Discussion on the training program of digital talents in the new era
- 个人对卷积神经网络的理解
- 记一次使用Windbg分析内存“泄漏”的案例
- [paddlepaddle] paddedetection face recognition custom data set
- 破解湖+仓混合架构顽疾,星环科技推出自主可控云原生湖仓一体平台
- 快速生成ipa包
猜你喜欢
U-Net: Convolutional Networks for Biomedical Images Segmentation
使用JMeter录制脚本并调试
About Statistical Power(统计功效)
Trust counts the number of occurrences of words in the file
Wu Enda team 2022 machine learning course, coming
寻找第k小元素 前k小元素 select_k
华夏基金:基金行业数字化转型实践成果分享
vs2017 qt的各种坑
《2022中国信创生态市场研究及选型评估报告》发布 华云数据入选信创IT基础设施主流厂商!
第十一届中国云计算标准和应用大会 | 华云数据成为全国信标委云计算标准工作组云迁移专题组副组长单位副组长单位
随机推荐
【在优麒麟上使用Electron开发桌面应】
Problems encountered in the project u-parse component rendering problems
node_exporter内存使用率不显示
Failed to virtualize table with JMeter
Electron installation problems
分享:中兴 远航 30 pro root 解锁BL magisk ZTE 7532N 8040N 9041N 刷机 刷面具原厂刷机包 root方法下载
数值计算方法 Chapter8. 常微分方程的数值解
Clickhouse (03) how to install and deploy Clickhouse
Sophon CE Community Edition is online, and free get is a lightweight, easy-to-use, efficient and intelligent data analysis tool
Sibling components carry out value transfer (there is a sequence displayed)
Sophon base 3.1 launched mlops function to provide wings for the operation of enterprise AI capabilities
About statistical power
Check namespaces and classes
Exemple Quelle est la relation entre le taux d'échantillonnage, l'échantillon et la durée?
图像分类,看我就够啦!
[QNX Hypervisor 2.2用户手册]6.3.2 配置VM
Generate classes from XML schema
Use of print function in MATLAB
Writing writing writing
vs2017 qt的各种坑