How to use set operations union in Python?
In Python, you can use the union operation on sets to combine elements from two or more sets into a new set without duplicates.
The union operation returns a new set containing all the unique elements from the sets involved.
# Create two sets
set1 = {1, 2, 3, 4}
set2 = {3, 4, 5, 6}
# Perform union operation
union_set = set1.union(set2)
Syntax
# Using the union() method
result_set = set1.union(set2, set3, …)
How to use set operations union in Python
# Create two sets
set1 = {1, 2, 3, 4}
set2 = {3, 4, 5, 6}
# Perform union operation
union_set = set1.union(set2)
print(union_set)
# Output: {1, 2, 3, 4, 5, 6}