Set_Methods_Python
Set_Methods_Python
Example:
- union(other_set): Returns a new set with all elements from both sets.
- difference(other_set): Returns a set with elements in the first set but not in the second.
Example:
set1 = {1, 2, 3}
set2 = {3, 4, 5}
print(set1.union(set2)) # {1, 2, 3, 4, 5}
print(set1.intersection(set2)) # {3}
print(set1.difference(set2)) # {1, 2}
print(set1.symmetric_difference(set2)) # {1, 2, 4, 5}
5. Copying a Set
Example: