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'}

Pictorial Presentation:

NumPy Sets: Shallow copy of sets.

Visualize Python code execution:

The following tool visualize what the computer is doing step-by-step as it executes the said program:

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to check if a set is a subset of another set.
Next: Write a Python program to clear a set.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz

Python: Tips of the Day

Python: Time library

Time library provides lots of time related functions and methods and is good to know whether you're developing a website or apps and games or working with data science or trading financial markets. Time is essential in most development pursuits and Python's standard time library comes very handy for that.

Let's check out a few simple examples:


import time