Computer Science

What do you understand by true copy of a list? How is it different from shallow copy?

Python List Manipulation

44 Likes

Answer

True copy of a list means that the elements of the original list are copied to new memory locations and the new list contains references to these new memory locations for each element of the list. Hence, in case of true copy changes made to the original list will not reflect in the copied list and vice versa.

Incase of shallow copy of a list, the elements of the original list are not copied to new memory locations. Both the new list and the original list refer to the same memory locations for the elements of the list. Hence, changes made to one of the list reflect in the other list as well.

Answered By

25 Likes


Related Questions