table of Contents
@
1. Description
Any variable data types are involved copying shades
However tuples, constants, immutable data type, regardless of shallow copy, a deep copy is pointing
regardless of nesting, once involves variable data type, there will be differences depth
special attention tuple slices shallow copy, variable data type not used anyway always shallow copy deepcopy
Shallow copy:
a variable name equal to another thing it must be pointed shallow copy is a copy of the top -> copy.copy ()
deep copy:
a copy of all copy.deepcopy
2. Code
# a = 1
# b = a
# print(id(a),id(b))
import copy
a = [11,22]
# c = copy.deepcopy(a)
# print(id(a),id(c))
def test(nums):
nums.append(3)
test(a)
print(a)
test(nums=copy.deepcopy(a))
print(a)
About the Author
Personal blog site
personal GitHub address
individual public number: