Python set copy

The Python copy method is used to copy the complete set items into a completely new one and the syntax of it is 

set.copy()

Python set copy example

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

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 copy function on numeric set

TIP: Please refer to the set in Python.

numeric = {15, 25, 35, 45, 55}
 
print('The Original : ', numeric )
 
copy_of_numeric = numeric.copy()

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