The Porta Westfalica, also known as the Westphalian Gap, is a gorge and water gap where the Weser river breaks through the passage between the mountain chains of the Wiehen Hills in the west and the Weser Hills (part of the Weser Uplands) in the east. It is located in the district of Minden-Lübbecke in North Rhine-Westphalia, Germany.
Photo by David Maciejewski on Unsplash

In the last article, we saw how we can find the difference between 2 sets in Python. In this article, we are going to see how to find the union of 2 sets.

This is actually quite similar to the difference.

We also have 2 ways to do the union of 2 sets in Python.

Let us say that we have 2 sets like the following:

If we want to find their union, we can simply use the *union()* method like the following:

We can also use the same method to find the union of 2 lists:

In fact, we can find the union of 2 lists even by using the plus sign, as shown below:

This plus operator only works for lists, but not for sets.

However, there is another sign that works for the union of sets: the pipe operator:

This only works for sets and not for lists.

That’s basically it.

I hope you find it useful.