当前位置:网站首页>Copy & Deepcopy
Copy & Deepcopy
2022-06-28 08:45:00 【Wang jijiya】
- copy() Used to copy values from lists or dictionaries , It's not copying references . In the following code ,a and a_copy There are two different lists , They don't affect each other .
- deepcopy() You can copy the sub lists contained in the list . As you can see in the following code ,copy() Only a single level list is copied , and deepcopy() Nested list copied .
import copy a = [1,2,3] b = [1, 2, [3, 4]] a_copy = a.copy() a_deepcopy = copy.deepcopy(a) b_copy = b.copy() b_deepcopy = copy.deepcopy(b) print(a == a_copy, a==a_deepcopy, a_copy==a_deepcopy) print(a is a_copy, a is a_deepcopy, a_copy is a_deepcopy) # Output: True True True # False False False print("a:",a, "a_copy:",a_copy, "a_deepcopy:",a_deepcopy) print("b:",b, "b_copy:",b_copy, "b_deepcopy:",b_deepcopy) # Output: a: [1, 2, 3] # a_copy: [1, 2, 3] # a_deepcopy: [1, 2, 3] # b: [1, 2, [3, 4]] # b_copy: [1, 2, [3, 4]] # b_deepcopy: [1, 2, [3, 4]] a[0] = 4 a.append(5) b[2][0] = "c" b.append(3) b.append([7,8]) print("a:",a, "a_copy:",a_copy, "a_deepcopy:",a_deepcopy) print("b:",b, "b_copy:",b_copy, "b_deepcopy:",b_deepcopy) # Output:a: [4, 2, 3, 5] # a_copy: [1, 2, 3] # a_deepcopy: [1, 2, 3] # b: [1, 2, ['c', 4], 3, [7, 8]] # b_copy: [1, 2, ['c', 4]] # b_deepcopy: [1, 2, [3, 4]]
边栏推荐
猜你喜欢

MATLAB小技巧(20)矩阵分析--主成分回归

Large current and frequency range that can be measured by Rogowski coil

Basic operation of PMP from applying for the exam to obtaining the certificate, a must see for understanding PMP
![[untitled]](/img/bb/213f213c695795daecb81a4cf2adcd.jpg)
[untitled]

与普通探头相比,差分探头有哪些优点

Love analysis released the 2022 love analysis · it operation and maintenance manufacturer panorama report, and an Chao cloud was strongly selected!

罗氏线圈可以测量的大电流和频率范围
![DELL R730服务器开机报错:[XXX] usb 1-1-port4: disabled by hub (EMI?), re-enabling...](/img/90/425965ca4b3df3656ce2a5f4230c4b.jpg)
DELL R730服务器开机报错:[XXX] usb 1-1-port4: disabled by hub (EMI?), re-enabling...

How to suppress SiC MOSFET crosstalk?

Build an integrated kubernetes in Fedora
随机推荐
Fire fighting work and measures in Higher Vocational Colleges
[learning notes] search
Error: `brew cask` is no longer a `brew` command. Use `brew <command> --cask` instead.
FatMouse and Cheese
Fire safety hazards
Modifying the SSH default port when installing Oracle RAC makes CRS unable to install
状态机程序框架
Maintenance and protection of common faults of asynchronous motor
Potential safety hazards in elderly care facilities
[learning notes] differential constraint
WasmEdge 0.10.0 发布!全新的插件扩展机制、Socket API 增强、LLVM 14 支持
如何抑制SiC MOSFET Crosstalk(串扰)?
FFMpeg (一) av_register_all()
[cloud native | kubernetes] in depth understanding of pod (VI)
找合适的PMP机构只需2步搞定,一查二问
temple
Not so Mobile
Discussion on the improvement and application of the prepayment system in the management of electricity charge and price
Large current and frequency range that can be measured by Rogowski coil
Discussion on the practice of fire emergency lighting system in the field of building electrical design