[issue14112] tutorial intro talks of "shallow copy" concept without explanation

Terry J. Reedy report at bugs.python.org
Sun Feb 26 01:12:04 CET 2012


Terry J. Reedy <tjreedy at udel.edu> added the comment:

'Shallow' is a common English word: "Stay in shallow water until you learn to swim!" But that is not the issue here.

I think the underlying issue is that the first sentence "All slice operations return a new list containing the requested elements." is wrong. Python lists, like shopping lists, do not 'contain' objects. Both contain references to objects (copies of their identifieres) and thereby define an abstract collection. A shallow copy of a collection object copies references (ids). A deep copy also copies objects themselves. (The Wikipedia article says much the same, but to me much less clearly.) 

If we start with a true sentence "Slice operations return a new list containing references to a subsequence of the original elements." or "Slice operations return a new list that defines a subsequence of the original sequence of objects", then I do not think more *needs* to be said. We could optionally add "Since no objects are copied, slices are shallow copies." both to emphasize that no objects are copied and to introduced the notion of shallow copy.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14112>
_______________________________________


More information about the Python-bugs-list mailing list