Post

@PythonPr b = a
Links to the same value in the memory
b = a.copy()
Creates a new set of valves in the memory
English

@PythonPr In 1st case the pointer points to object 'a', so that any changes made in 'a' will reflect in object 'b'.
In 2nd case the replica of object 'a' has been created, so no more connection between 'a' and 'b', any changes made in the object 'a' will no longer affect the object 'b'.
English

@PythonPr 1. Reference:pointing to the same memory
2. Deep copy: pointing to different values in the memory
Dhaka, Bangladesh 🇧🇩 English

@PythonPr The copy method creates a shallow copy of the list. A new object in memory is created.
English

@PythonPr case 1: a is the same as b meaning a change in a affects b
case 2: exact replica but a change in a doesn't affect b
English

@PythonPr Reference vs shallow copy. But copy() is still shallow. Nested mutables remain shared references. The gotchas have layers.
English

@PythonPr In simple terms:
1st is person just different name to call out
2nd is shadow clone jutsu 🤣
English

@PythonPr 1. assignment op never makes a copy, it still refers to the original object
2. copy/deepcopy ops only changes new assignment
English

@PythonPr fundamental concept in Python: Reference vs. Value
b=a(Reference Assignment)
They are two names for the same thing
b = a.copy()
In this case, .copy() creates a new,independent list object in memory and assigns it to b.
b is a separate object that contain the same values as a.
English

In the top section when we copy a to b it also copied reference so any change in either of these will reflect in both.
id(a) = id(b)
In the second section, it actually copy only value from a to b and creates a new reference, hence any change in either a or b will not reflect in each other
id(a) ≠ id(b)
English






