Python Practice › Set Programs › Program 6
Union of two sets
Write a Python program to find the union of two sets.
Input
{1, 2, 3}, {3, 4, 5}Output
{1, 2, 3, 4, 5} {1, 2, 3, 4, 5}Approach
|orunion().
Solution
a, b = {1, 2, 3}, {3, 4, 5}print(a | b, a.union(b))Output
{1, 2, 3, 4, 5} {1, 2, 3, 4, 5}Learn the concept
New to this topic? Read the lesson, then come back.