First create an object in Python, and then point the variable to the object you created.
For each object, there is a header message that marks the object's type information in the message. Whenever a variable name is given a new object, the space occupied by the previous object is recycled (if the object is not referenced by another variable name or object). Also, in Python, each object has a counter that records the number of times the object is referenced, and when the counter is set to 0 o'clock, the memory space occupied by the object is freed, which is garbage collection.
Shared references:
In Python, a variable is always a pointer to an object, not a memory area label that can be changed. Give a variable a new value, not replace the original object, but let the variable to refer to a new object, the actual effect is to re-assign the value of the variable, which will only affect the re-assigned variable.
Also, here is the operator "= =" and "is".
= =, in the same way as the C language, tests the values of the two referenced objects in a consistent way;
is, checks the identity of two objects, determines whether two object names point to the same address space, and returns True if it is. ,
Create two list objects, even if their values are the same, from different spaces. So is the comparison result is false
Maybe some friends have tested an example, the result is actually return true. This does not mean that they point to the same object, but in memory, small integers and strings are cached and reused , so is only tells us that A and B refer to the same object.
References and shared references to objects in Python