In Python, you can copy a set using the copy()
method or the set()
constructor. This creates a new set with the same elements.
Python में आप copy()
method या set()
constructor का उपयोग करके एक set की copy बना सकते हैं। इससे एक नया set बनता है जिसमें वही elements होते हैं।
copy()
MethodCreates an exact duplicate of a set.
Set की exact copy बनाता है।
original = {"apple", "banana", "cherry"}
copy_set = original.copy()
print(copy_set)
Output:
{'banana', 'cherry', 'apple'}
set()
ConstructorAlso creates a new set with same items.
Set constructor भी एक नई copy बनाता है।
original = {"x", "y", "z"}
new_set = set(original)
print(new_set)
Output:
{'x', 'y', 'z'}
copy()
and set()
return shallow copies. If you modify the new set, it does not affect the original.