Deep vs shallow copy

import copy
a = [4]b = copy.copy(a)
>>> b
[4]
>>> id(a)
140122699353672
>>> id(b)
140122699353864
>>> a = [[1], [2], [3]]
>>> b = copy.copy(a)
>>> a.append([6])
>>> a
[[1], [2], [3], [6]]
>>> b
[[1], [2], [3]]
>>> a[2][0] = 4
>>> a
[[1], [2], [4], [6]]
>>> b
[[1], [2], [4]]
>>> b = copy.deepcopy(a)
>>> a
[[1], [2], [4], [6]]
>>> b
[[1], [2], [4], [6]]
>>> a[2][0] = 8
>>> a
[[1], [2], [8], [6]]
>>> b
[[1], [2], [4], [6]]
>>>

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store