low-angle photography of brown concrete building during daytime
Photo by Samuel-Elias Nadler on Unsplash

If you have to find the union of elements that are either in the first or the second set, but not in both of them, then you need to use the symmetric difference.

This is also another math operation between sets that you have probably seen in a math class in high school.

This can be done quite easily and quickly using 2 built-in methods in Python.

Let’s start with the first one.

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

Now we can simply find the symmetric difference as shown below:

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

There is another method to find it which is by using the operator &:

That’s basically it.

I hope you find it useful.