On this page
copy.deepcopy
Prev: copy.copy | Up: copy | Next: copy.Error
Rel: copy.copy, copy.Error, copy.replace
Ref: docs.python.org — copy.deepcopy
Tags: #public #python3 #stdlib #copy
Import
import copy
from copy import deepcopy
Signature & Overview
copy.deepcopy(x, memo=None, _nil=[])
Deep copy operation on arbitrary Python objects.
Usage
import copy
orig = {"nested": [1, 2]}
deep = copy.deepcopy(orig)
deep["nested"].append(3)
assert orig["nested"] == [1, 2] and deep["nested"] == [1, 2, 3]
Gotchas
- Much slower than shallow copy: Handles cyclic references via
memo, but cannot copy open files, locks, sockets, or generators.
REPL Inspect
from copy import deepcopy
help(deepcopy)
Linked from
Related notes
- tuts/python3/stdlib_module/copy/copy Linked here; links to this page; shared tags: #copy, #stdlib
- tuts/python3/stdlib_module/copy/Error Linked here; links to this page; shared tags: #copy, #stdlib
- tuts/python3/stdlib_module/copy/replace Linked here; links to this page; shared tags: #copy, #stdlib
- tuts/python3/stdlib_module/copy links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib
- tuts/c/stdlib/assert/static_assert shared tags: #stdlib
- tuts/c/stdlib/ctype shared tags: #stdlib
- tuts/c/stdlib/ctype/isalpha shared tags: #stdlib