w3resource logo
Python Exercises

Python Exercise: Union of sets

Python sets: Exercise-7 with Solution

Write a Python program to create a union of sets.

Sample Solution:-

Python Code:

#Union
setx = set(["green", "blue"])
sety = set(["blue", "yellow"])
seta = setx | sety
print(seta)

Sample Output:

{'yellow', 'green', 'blue'} 

Python Code Editor:

#Union
setx = set(["green", "blue"])
sety = set(["blue", "yellow"])
seta = setx | sety
print(seta)

Improve this sample solution and post your code through Disqus