当前位置:网站首页>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 .
边栏推荐
- Access the database and use redis as the cache of MySQL (a combination of redis and MySQL)
- Image classification, just look at me!
- Sophon CE社区版上线,免费Get轻量易用、高效智能的数据分析工具
- 寻找第k小元素 前k小元素 select_k
- 第十一届中国云计算标准和应用大会 | 华云数据成为全国信标委云计算标准工作组云迁移专题组副组长单位副组长单位
- 图片数据不够?我做了一个免费的图像增强软件
- U-Net: Convolutional Networks for Biomedical Images Segmentation
- [paddlepaddle] paddedetection face recognition custom data set
- About Statistical Power(统计功效)
- Electron安装问题
猜你喜欢

vs2017 qt的各种坑

JVM third talk -- JVM performance tuning practice and high-frequency interview question record

吴恩达团队2022机器学习课程,来啦

About Estimation with Cross-Validation
![含重复元素取不重复子集[如何取子集?如何去重?]](/img/b2/d019c3f0b85a6c0d334a092fa6c23c.png)
含重复元素取不重复子集[如何取子集?如何去重?]

Sophon AutoCV:助力AI工业化生产,实现视觉智能感知

Find the first k small element select_ k

node_ Exporter memory usage is not displayed

buuctf-pwn write-ups (9)

Record eval() and no in pytoch_ grad()
随机推荐
寻找第k小元素 前k小元素 select_k
记录Pytorch中的eval()和no_grad()
[QNX Hypervisor 2.2用户手册]6.3.2 配置VM
快速生成ipa包
Sophon base 3.1 launched mlops function to provide wings for the operation of enterprise AI capabilities
RPC协议详解
吳恩達團隊2022機器學習課程,來啦
《2022中国信创生态市场研究及选型评估报告》发布 华云数据入选信创IT基础设施主流厂商!
Huaxia Fund: sharing of practical achievements of digital transformation in the fund industry
Login and connect CDB and PDB
Introduction to VC programming on "suggestions collection"
使用JMeter录制脚本并调试
vs2017 qt的各种坑
Sibling components carry out value transfer (there is a sequence displayed)
记一次使用Windbg分析内存“泄漏”的案例
图像分类,看我就够啦!
华夏基金:基金行业数字化转型实践成果分享
vulnhub之darkhole_2
Nanjing University: Discussion on the training program of digital talents in the new era
U-Net: Convolutional Networks for Biomedical Images Segmentation