Python set copy

The Python set copy method is used to copy the complete set items into a completely new set. The syntax of this Python set copy method is 

set.copy()

Python set copy example

In this example, we declared a set of fruits. Next, we used this set copy function to copy fruit_set into copy_of_fruit_set.

# Python set copy
fruits_set = {'Mango', 'Cherry', 'Apple', 'Kiwi'}
 
print('The Original Set : ', fruits_set )
 
copy_of_fruits_set = fruits_set.copy()
print('The Copied Set   : ', copy_of_fruits_set )
Python set copy method 1

This time we are using the Python set copy function on numeric set

TIP: Please refer to the Python set in Python.

numeric_set = {15, 25, 35, 45, 55}
 
print('The Original Set : ', numeric_set )
 
copy_of_numeric_set = numeric_set.copy()

print('The Copied Set   : ', copy_of_numeric_set )
The Original Set :  {35, 55, 25, 45, 15}
The Copied Set   :  {35, 55, 25, 45, 15}