To copy a set in Python, you can use either the copy() method or the built-in set() function.
Using the copy() method:
# create a set
my_set = {1, 2, 3}
# copy the set
new_set = my_set.copy()
# print the sets
print(my_set) # output: {1, 2, 3}
print(new_set) # output: {1, 2, 3}
Using the set() function:
# create a set
my_set = {1, 2, 3}
# copy the set
new_set = set(my_set)
# print the sets
print(my_set) # output: {1, 2, 3}
print(new_set) # output: {1, 2, 3}
Both methods create a new set that is a copy of the original set. Note that the new set is a completely separate object, so modifying it will not affect the original set.