set.copy() Shallow copy
Last updated: 2026-09-22
set.copy() Shallow copy
set.copy() returns a shallow copy.
| Category | Set Methods |
|---|---|
| Kind | Built-in Type Method |
| Python Version | all |
📝 Syntax
set.copy()
Returns:A new set that is a shallow copy.
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}
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QIs copy() a shallow copy?
AYes. However, since set elements must be immutable (hashable) objects, the actual effect of shallow and deep copy is the same.
QDoes the copied set affect the original set?
ANo; modifying the new set does not change the original set.
QWhat type does copy() return?
AA new set object with the same contents as the original, independent and not interfering with it.