dict.copy() Shallow copy
Last updated: 2026-09-22
dict.copy() Shallow copy
dict.copy() returns a shallow copy of the dict.
| Category | Dict Methods |
|---|---|
| Kind | Built-in Type Method |
| Python Version | all |
📝 Syntax
dict.copy()
Returns:A new dict that is a shallow copy (value objects are shared).
Mutates the original:No (returns a new object)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
[1, 2, 3]
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QIs copy() a deep copy or a shallow copy?
AA shallow copy. After d2 = d.copy(), d2 and d share the value objects inside: if a value is a mutable object such as a list, changing one affects the other.
QHow do I fully copy a nested dict?
AUse copy.deepcopy(d) (you need to import copy).
QWhat is the difference from dict(d)?
AThey are equivalent; both are shallow copies and interchangeable.