Copy & Deepcopy in Python

1
2
3
4
5
6
7
8
9
a = [1,2,3]
b = [a,a,a]
# Copy
c = b
d = b.copy()
# b c d all point at the same object. if one of the them is changed, all of them are changed.
from copy import deepcopy
f = deepcopy(b)
# python offers a function called deepcopy that allows to create a new object so that you can do anything with f while there is no influence on b.