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.
Headings of Contents
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.
Syntax
symmetric_difference function in python is:-
set.symmetric_difference(set)
Parameter
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.
Example:
set1 = { 'Python', 'Java', 'JavaScript', 'C++'}
set2 = {'Python', 'HTML', 'JavaScript', 'Bootstrap'}
result = set1.symmetric_difference(set2)
print(result)
Output
{'Java', 'C++', 'HTML', 'Bootstrap'}
Conclusion
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
- Set add() method
- Set clear() method
- Set difference() method
- Set difference_update() method
- Set discard() method
- Set intersection() method
- Set intersection_update() method
For more information:- Click here