Menu Close

Python Set symmetric_difference() Method

python set symmetric_difference

In this example, we will discuss the set symmetric_difference method using various examples.
Python set symmetric_difference() method is used to return set items from both sets, but not the items that are present in both sets.

To understand this example, you should have basic knowledge of python set.

Python set symmetric_difference method

symmetric_difference is used to return a set that contains the items from both sets, except the items that are present in both sets.


symmetric_difference function in python is:-



symmetric_difference function in python accepts one parameter:-

  • set – Required. set to check in.

Python set symmetric_difference example

Here we will use symmetric_difference function in python to return new set.


set1 = { 'Python', 'Java', 'JavaScript', 'C++'}
set2 = {'Python', 'HTML', 'JavaScript', 'Bootstrap'}
result = set1.symmetric_difference(set2)


{'Java', 'C++', 'HTML', 'Bootstrap'}


In this python set method tutorial, you have learned all about the python set symmetric_difference() method create a new set which contains items from both sets, but not the items that are present in both sets.

I hope this article will help you, please keep visiting to continue for further python methods.

Other set methods

For more information:- Click here

Python Set remove() Method
Python Set union() Method

Was this post helpful?

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *