To find the union of two sets in Python, you can use the union operator | or the union() method.
In this example,
set1
and set2
, containing some elements.set1
and set2
.set1 = {1, 2, 3}
set2 = {3, 4, 5}
union_set = set1 | set2
print('Union of set1 and set2:')
print(union_set)
Union of set1 and set2: {1, 2, 3, 4, 5}
In this example,
set1
and set2
, containing some elements.set1
and set2
.set1 = {1, 2, 3}
set2 = {3, 4, 5}
union_set = set1.union(set2)
print('Union of set1 and set2:')
print(union_set)
Union of set1 and set2: {1, 2, 3, 4, 5}
In this tutorial, we learned How to find Union of Two Sets in Python language with well detailed examples.