当前位置:网站首页>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 .
边栏推荐
- GIMP 2.10教程「建议收藏」
- node_exporter内存使用率不显示
- 分享:中兴 远航 30 pro root 解锁BL magisk ZTE 7532N 8040N 9041N 刷机 刷面具原厂刷机包 root方法下载
- 星环科技数据安全管理平台 Defensor重磅发布
- Record eval() and no in pytoch_ grad()
- 图扑软件数字孪生 | 基于 BIM 技术的可视化管理系统
- Notes on common management commands of openshift
- Login and connect CDB and PDB
- Sophon KG升级3.1:打破数据间壁垒,解放企业生产力
- 金太阳开户安全吗?万一免5开户能办理吗?
猜你喜欢
buuctf-pwn write-ups (9)
node_ Exporter memory usage is not displayed
LeetCode 6111. Spiral matrix IV
Copy the linked list with random pointer in the "Li Kou brush question plan"
node_exporter内存使用率不显示
LeetCode 6109. Number of people who know the secret
U-Net: Convolutional Networks for Biomedical Images Segmentation
@Extension、@SPI注解原理
To solve the stubborn problem of Lake + warehouse hybrid architecture, xinghuan Technology launched an independent and controllable cloud native Lake warehouse integrated platform
ViewPager + RecyclerView的内存泄漏
随机推荐
分享:中兴 远航 30 pro root 解锁BL magisk ZTE 7532N 8040N 9041N 刷机 刷面具原厂刷机包 root方法下载
记录Pytorch中的eval()和no_grad()
彻底理解为什么网络 I/O 会被阻塞?
开户注册挖财安全吗?有没有风险的?靠谱吗?
【在優麒麟上使用Electron開發桌面應】
Wu Enda team 2022 machine learning course, coming
如何获取飞机穿过雷达两端的坐标
Sibling components carry out value transfer (there is a sequence displayed)
Is it safe to open an account and register stocks for stock speculation? Is there any risk? Is it reliable?
金太阳开户安全吗?万一免5开户能办理吗?
Fix vulnerability - mysql, ES
在通达信上做基金定投安全吗?
使用Jmeter虚拟化table失败
JVM third talk -- JVM performance tuning practice and high-frequency interview question record
数值计算方法 Chapter8. 常微分方程的数值解
Sophon Base 3.1 推出MLOps功能,为企业AI能力运营插上翅膀
Numerical calculation method chapter8 Numerical solutions of ordinary differential equations
Generate classes from XML schema
Cronab log: how to record the output of my cron script
How to improve the thermal management in PCB design with the effective placement of thermal through holes?