当前位置:网站首页>Example 007: copy data from one list to another list.
Example 007: copy data from one list to another list.
2022-07-05 08:22:00 【Lazy smile】
example 007:copy
subject : Copy data from one list to another .
Program analysis :
We can use the following methods to copy : Direct assignment =、 Indexes [:]、copy()、deepcopy()
The code is as follows :
import copy
a = [1, 2, 3, 4, ['a', 'b']]
b = a # assignment
c = a[:] # Shallow copy
d = copy.copy(a) # Shallow copy
e = copy.deepcopy(a) # Deep copy
a.append(5)
a[4].append('c')
print('a=', a)
print('b=', b)
print('c=', c)
print('d=', d)
print('e=', e)a= [1, 2, 3, 4, ['a', 'b', 'c'], 5]
b= [1, 2, 3, 4, ['a', 'b', 'c'], 5]
c= [1, 2, 3, 4, ['a', 'b', 'c']]
d= [1, 2, 3, 4, ['a', 'b', 'c']]
e= [1, 2, 3, 4, ['a', 'b']]
summary :
"""
Deep copy , Depth of copy : I have opened up a new memory , Copy all the copied contents
Deep copy of the list is to change the new list no matter how ( Unidimensional or Multidimensional ), The original list remains unchanged .
Shallow copy , The degree of copying is shallow , Only the first address of the original data is copied , Then through the first address of the original data , To get content .
Shallow copy , For multidimensional lists , Only the first dimension deep copy
"""
边栏推荐
- Shell script
- WiFi wpa_ Detailed description of supplicant hostpad interface
- Summary -st2.0 Hall angle estimation
- Verilog -- state machine coding method
- Hardware 3 -- function of voltage follower
- Management and use of DokuWiki (supplementary)
- Soem EtherCAT source code analysis II (list of known configuration information)
- [NAS1](2021CVPR)AttentiveNAS: Improving Neural Architecture Search via Attentive Sampling (未完)
- Charge pump boost principle - this article will give you a simple understanding
- Measurement fitting based on Halcon learning [II] meaure_ pin. Hdev routine
猜你喜欢

剑指 Offer 09. 用两个栈实现队列

leetcode - 445. 两数相加 II

Class of color image processing based on Halcon learning_ ndim_ norm. hdev

Explain task scheduling based on Cortex-M3 in detail (Part 1)

Matlab2018b problem solving when installing embedded coder support package for stmicroelectronic

Talk about the circuit use of TVs tube

Take you to understand the working principle of lithium battery protection board

C, Numerical Recipes in C, solution of linear algebraic equations, LU decomposition source program

实例003:完全平方数 一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?

实例008:九九乘法表
随机推荐
Shape template matching based on Halcon learning [viii] PM_ multiple_ models. Hdev routine
Brief discussion on Buck buck circuit
【三层架构】
Buildroot system for making raspberry pie cm3
剑指 Offer 06. 从尾到头打印链表
Google sitemap files for rails Projects - Google sitemap files for rails projects
Verilog -- state machine coding method
Step motor generates S-curve upper computer
C WinForm [exit application] - practice 3
Several important parameters of LDO circuit design and type selection
[NAS1](2021CVPR)AttentiveNAS: Improving Neural Architecture Search via Attentive Sampling (未完)
More than 90% of hardware engineers will encounter problems when MOS tubes are burned out!
Classic application of MOS transistor circuit design (2) - switch circuit design
STM32 --- GPIO configuration & GPIO related library functions
动力电池UL2580测试项目包括哪些
PMSM dead time compensation
Class of color image processing based on Halcon learning_ ndim_ norm. hdev
Synchronization of QT multithreading
Halcon's practice based on shape template matching [2]
Some thoughts on extracting perspectives from ealfa and Ebeta