Photo by Fabian Stroobants on Unsplash

There can be cases when you may need to find the difference between 2 sets in Python. If you do not remember from high school, the difference between 2 sets means that we get the elements from the first set that are not in the second set.

We can do that quite easily in Python using the minus operator.

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

If we want to find their difference, we can simply use the minus operator as shown below:

That’s quite easy, right?

We can also do the same using the difference() method:

That’s basically it.

I hope you find it useful.