xxxxxxxxxx
firstSet = {2, 3, 4, 5}
secondSet = {1, 3, 5, 7}
print(firstSet | secondSet)
# {1, 2, 3, 4, 5, 7}
xxxxxxxxxx
s1 = {'Python', 'Java'}
s2 = {'C#', 'Java'}
s = s1.union(s2)
print(s)
xxxxxxxxxx
# Creating two sets
set1 = {1, 2, 3, 4}
set2 = {3, 4, 5, 6}
# Using the union() method to combine the sets
union_set = set1.union(set2)
# Printing the resulting set
print(union_set)
xxxxxxxxxx
set_1 = {1, 2, 3, 4, 5}
set_2 = {3, 4, 5, 6}
# Method 1
union_1 = set_1 | set_2 # {1, 2, 3, 4, 5, 6}
# Method 2
union_2 = set_1.union(set_2) # {1, 2, 3, 4, 5, 6}
xxxxxxxxxx
set1 = {0, 2, 4, 6, 8}
set2 = {1, 3, 5, 7, 9}
result = set1.union(set2)
print(result)