w3resource logo


Python Exercises

Python Exercise: Shallow copy of sets

Python sets: Exercise-11 with Solution

Write a Python program to create a shallow copy of sets.

Note : Shallow copy is a bit-wise copy of an object. A new object is created that has an exact copy of the values in the original object.

Sample Solution:-

Python Code:

setp = set(["Red", "Green"])
setq = set(["Green", "Red"])
#A shallow copy
setr = setp.copy()

Sample Output:

{'Red', 'Green'}

Python Code Editor:

Improve this sample solution and post your code through Disqus