Home >Backend Development >Python Tutorial >python list copy
If we need to copy a list, we can use a special method, which I will tell you today.
I first define a list
a=[1,2,34]
Then I check the address of the object through the built-in method id()
print id(a)
Object address: 11488352
Then I Copy a list of a and copy it to the variable b
b = a[:]
I output the variable b
print b
The result is [1, 2, 34], which is the same as a, and then I Look at the address in List B below.
print id(b)
Object address: 11511448
It can be seen that the addresses of the two objects are different, indicating that a new list object is generated by re-copying, not the assignment of a reference.