Python set copy

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

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 )
set copy Example 1

This time we are using the copy function on a 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}