[docs] [issue23406] interning and list comprehension leads to unexpected behavior
R. David Murray
report at bugs.python.org
Fri Sep 4 16:23:13 CEST 2015
R. David Murray added the comment:
What is actually happening is that the *contents* of the list are copied, but the list itself is not. This is a consequence of the definition in terms of +. So, yes, that is a shallow copy, but not quite in the sense that mylist.copy() is a shallow copy, since the references to the contents of s get appended to the list being constructed by *, not a new list that is a "copy" of s.
You are correct that "s is only referenced" is not really accurate. But how about "Note that the contents of the *s* object are not copied, they are referenced multiple times". I think that highlights the source of the confusion: that the *contents* are not copied.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23406>
_______________________________________
More information about the docs
mailing list