Home >>Python Set Methods >Python Set symmetric_difference() Method

Python Set symmetric_difference() Method

Python Set symmetric_difference() Method

Python set symmetric_difference() method is used to return a set that contains all the items from both set but not the items that are present in both the sets.

Syntax:
set.symmetric_difference(set)

Parameter Values

Parameter Description
set This is a required parameter. It defines the set to check for matches in.
Here is an example of Python symmetric_difference() method:

x = {"Abhi", "Jerry", "Mickey"}
y = {"Wings", "Alpha", "Jerry"}
z = x.symmetric_difference(y) 
print(z)

Output:
{'Wings', 'Mickey', 'Alpha', 'Abhi'}
Example 2:

x = {"Abhi", "Jerry", "Mickey"}
y = {"Wings", "Alpha", "Jerry"}
z = y.symmetric_difference(x) 
print(z)

Output:
{'Wings', 'Abhi', 'Alpha', 'Mickey'}

No Sidebar ads