a = {
1:[1,2,3]}
b = a: Assignment reference ,a and b They all point to the same object .
Be careful : Assignment in use “=” When , The original variable cannot be re assigned , Otherwise, the original variable will point to a new memory address . for example :
example 1:
# use "=" Perform assignment operation
a = [1,2,3]
b = a
a = [2,3,4]
print(a)
print(b)
""" result : [2, 3, 4] [1, 2, 3] """
example 2:
# The variable a Modify itself
a = [1,2,3]
b = a
a.append(99)
print(a)
print(b)
"""" result : [1, 2, 3, 99] [1, 2, 3, 99] """
b = a.copy(): Shallow copy , a and b Is a separate object , But their sub objects still point to the unified object ( Is quoted ).
copy Children of a complex object are not completely copied , For example, nested sequences in sequences , Nested sequences in the dictionary are all sub objects of complex objects . For child objects ,python It will be stored as a public image , All copies of him are treated as a reference .
b = copy.deepcopy(a): Deep copy , a and b It completely copies the parent object and its children , The two are completely independent .