mirror of
https://github.com/python/cpython.git
synced 2026-06-28 03:41:13 +00:00
[3.15] gh-150636: Clarify difference between copy.copy() and the copy() methods (GH-150637) (GH-150665)
(cherry picked from commit 1de909b324)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: Stan Ulbrych <stan@python.org>
This commit is contained in:
parent
c5655dfe51
commit
2fb2a23cbd
1 changed files with 7 additions and 3 deletions
|
|
@ -72,9 +72,13 @@ file, socket, window, or any similar types. It does "copy" functions and
|
|||
classes (shallow and deeply), by returning the original object unchanged; this
|
||||
is compatible with the way these are treated by the :mod:`pickle` module.
|
||||
|
||||
Shallow copies of dictionaries can be made using :meth:`dict.copy`, and
|
||||
of lists by assigning a slice of the entire list, for example,
|
||||
``copied_list = original_list[:]``.
|
||||
Shallow copies of many collections can be made using the corresponding
|
||||
:meth:`!copy` method (such as :meth:`list.copy`, :meth:`dict.copy` or
|
||||
:meth:`set.copy`), and of sequences (such as lists or bytearrays) by making
|
||||
a slice of the entire sequence (``sequence[:]``).
|
||||
However, these methods and slicing can create an instance of the base type
|
||||
when copying an instance of a subclass, whereas :func:`copy.copy` normally
|
||||
returns an instance of the same type.
|
||||
|
||||
.. index:: pair: module; pickle
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue