One. Variables, objects, references:
1. Variables:
2. Object: Contains a header information, the following two parts of the content
A. The data type of the object,
B. Reference counter: Records the number of current references to the object, and once the counter is zeroed, the object's memory space is reclaimed.
3. Reference: A pointer between an associative variable and an object,
A=3
Two. Shared references, newly created objects:
1. A=3
B=a
A= ' spam '
A changes, B is also equal to 3, because the object that B points to does not change, and B's pointer does not change.
2. A=3
B=a
A=a+2
b What's the situation?
Python assigns a new value to a variable, does not change the original object, is to recreate an object, and then point the new object pointer to the variable, the old object's counter will remove a reference
Three. To share the app, modify the object in place:
1. l1=[2,3,4]
L2=l1
L1[0]=24
L1 and L2 are changed to [24,3,4]
2. l1=[2,3,4]
l2=l1[:]
L1[0]=24
L1 is [24,3,4]l2=[2,3,4], because l1[:] is a copy-only object and does not create a reference.
Four. Shared references and equality:
1. ' = = ': Determine whether the value of two objects is the same
2. ' Is ': Determine the identity of two objects, i.e. whether two variables point to the same object
Python Learning note Eight--dynamic type