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)

Output :

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

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.



Join our Question Answer community to learn and share your programming knowledge.

Solve these problems:

Java: How to convert a string to an integer in Java?

C#: Loops in c#

SQL: JOIN using more than 5 tables