Skip to content
Set Methods

copy()

Return a shallow copy of the set.

set.copy()

set.copy() creates a new set with a duplicate of all elements from the original set.

Adding or removing elements in the copy does not alter the original set.

Returns

A new shallow copy of the set.

Try it

Run it and change it
original = {"alpha", "beta"}
backup = original.copy()
backup.add("gamma")
print("Original:", sorted(original))
print("Backup:", sorted(backup))

Worth knowing

  • Alternative syntax: set(original) produces an identical shallow copy.

Related entries