lis1 = [1, 2, 3, 4]
lis2 = lis1.copy()
print("The new list created is : " + str(lis2))
lis2.append(5)
print("The new list after adding new element : " + str(lis2))
print("The old list after adding new element to new list : " + str(lis1))
Output:
The new list created is : [1, 2, 3, 4]
The new list after adding new element : [1, 2, 3, 4, 5]
The old list after adding new element to new list : [1, 2, 3, 4]
here 5 is appended to list2, but it's not making any changes to list1 Whereas the reverse condition of appending 5 to list1 changes list2 why? doing shallow copy has to change both if the change is done for one, right?