Copy codeThe Code is as follows:
A = 3
B =
First (figure 1). You can see it at a Glance:
Variable name and object. After running the value assignment statement B = a, both variables a and B point to the memory space of object 3.
If a = 'python' is executed, a points to the created String object.
Let's try again:
Copy codeThe Code is as follows:
>>> List_1 = [1, 2, 4]
>>> List_2 = list_1
>>> List_2
>>> List_1 [0] = 'python'
>>> List_2
Result:
Copy codeThe Code is as follows:
[1, 2, 3, 4]
['Python', 2, 3, 4]
In my understanding, list is a type object, and every element in the object can be regarded as a variable, referencing the object list_1 = [1, 2, 3, 4] is to point list_1 to the memory space of the list. When list_2 = list_1, they will point to the same memory space. When the value of List_1 [0] is changed, list_2 still points to the list object, so the value of list_1 [0] is changed, in fact, python directly makes changes to the memory space through list_1, and there is no variable pointing to list_2.
Maybe this result is not what we want. If you do not want this to happen, you need to copy python objects instead of creating references.
For example: