In python 3.10.1 documentation(The Python Tutorial -> An Informal introduction to Python -> Lists)
[cid:image003.png@01D803C1.44B36A90]
Maybe it should be replaced by “deep copy” ?
Here is my try: [cid:image005.png@01D803C1.44B36A90]
On 07/01/2022 04:22, GC Toph wrote:
In python 3.10.1 documentation(The Python Tutorial -> An Informal introduction to Python -> Lists)
Maybe it should be replaced by “deep copy” ?
Here is my try:
Since integers are immutable (and not containers), what you have demonstrated is a shallow copy - in fact a deep and shallow copy are indistinguishable if the container being copied doesn't also contain other containers.
>>> a = [0,1, {2,3}] >>> b = a [:] >>> a is b False >>> a[2] is b[2] # Proves this is a shallow copy - a deepcopy would have made a replica of that set (but with the same contents). True >>> b[2].add(4) >>> a, b ([0, 1, set([2, 3, 4])], [0, 1, set([2, 3, 4])])
This shows that a slice is a shallow copy only - if it was a deepcopy then changing the set in b[2] wouldn't have also changed a[2]
docs mailing list --docs@python.org To unsubscribe send an email todocs-leave@python.org https://mail.python.org/mailman3/lists/docs.python.org/ Member address:anthony.flury@btinternet.com