A copy gives you another way to work with a value or container, but it may not be independent of the original. For mutable containers, the key distinction is between a shallow copy, which shares nested objects, and a deep copy, which copies them too. section 5.6
Choose a copying method based on the contents:
- For a list, a full slice such as x[:] makes a shallow copy; x + [] and x * 1 do too. section 5.6
- For a dictionary, use x.copy() for a shallow copy. Use copy.deepcopy(x) when nested mutable values should be independent. section 7.2
- For a tuple, these copy-like methods produce an alias, not a new object; the tuple itself cannot be modified. section 5.7.1
Nested lists
With original = [[0], 1], shallow = original[:] leaves both lists sharing the inner list: changing shallow[0][0] also changes original[0][0]. By contrast, deep = copy.deepcopy(original) keeps nested lists independent. section 5.6




