Post

@PythonPr Output is : [1,2,3]
Because
Y=X.copy() is created the copy of X and store in Variable Y
X.append(4) is added 4 at last index of X but not in Y
We print(Y) that's why Output is [1,2,3]
English

@PythonPr The copy() method for y becomes a shallow copy that is bound to the original list object (i.e., [1,2,3]). When 4 is appended to x, y is still bound to [1,2,3]. So print(y) gives [1,2,3]
English

@PythonPr My bad. I misread it as copy library.
list.copy returns completely new list
Hence any change in x will not reflect in y
Y will be [1,2,3]
we can use id(x) and id(y) to validate there addresses both will be different
English

@PythonPr [1, 2, 3]
You made a copy, not a reference. So changes to x don’t affect y.
Since copy() creates a new list, modifying x doesn’t affect y, so the output remains [1, 2, 3]
English
























