[issue45169] Shallow copy occurs when list multiplication is used to create nested lists; can confuse users

Steven D'Aprano report at bugs.python.org
Fri Sep 10 23:07:46 EDT 2021


Steven D'Aprano <steve+python at pearwood.info> added the comment:

This is not a bug. No copy is made at all, neither shallow nor deep.

This is described in the documentation for built-in types:

https://docs.python.org/3/library/stdtypes.html#common-sequence-operations

and is similar to the issue in the FAQs:

https://docs.python.org/3/faq/programming.html#id16


I acknowledge that this is sometimes confusing for beginners, but it is just one of those things that programmers have to learn. Sequence multiplication does not copy the items, it replicates references to the same item.

----------
nosy: +steven.daprano
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45169>
_______________________________________


More information about the Python-bugs-list mailing list