Table of Contents
The Python symmetric_difference() method returns the symmetric difference of two sets.
The symmetric difference of two sets A and B is the set of elements that are in either A or B, but not in their intersection.

The syntax of symmetric_difference() is:
A.symmetric_difference(B)
1. Example 1: Working of symmetric_difference()
A = {'a', 'b', 'c', 'd'}
B = {'c', 'd', 'e' }
C = {}
print(A.symmetric_difference(B))
print(B.symmetric_difference(A))
print(A.symmetric_difference(C))
print(B.symmetric_difference(C))
Output
{'b', 'a', 'e'}
{'b', 'e', 'a'}
{'b', 'd', 'c', 'a'}
{'d', 'e', 'c'}
2. Symmetric difference using ^ operator
In Python, we can also find the symmetric difference using the ^ operator.
A = {'a', 'b', 'c', 'd'}
B = {'c', 'd', 'e' }
print(A ^ B)
print(B ^ A)
print(A ^ A)
print(B ^ B)
Output
{'e', 'a', 'b'}
{'e', 'a', 'b'}
set()
set()
Related posts:
Python Program to Find All File with .txt Extension Present Inside a Directory
Deep Learning with Python - Francois Chollet
Python datetime
Python ord()
Python staticmethod()
Converting Between a List and a Set in Java
Python help()
Python Object Oriented Programming
Python oct()
Python String isalnum()
Python Dictionary clear()
Python Dictionary copy()
Python tuple()
Python Program to Display Fibonacci Sequence Using Recursion
Python Program to Convert Two Lists Into a Dictionary
Python String isupper()
Python setattr()
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python timestamp to datetime and vice-versa
Python Program to Create a Countdown Timer
Python Program to Check Armstrong Number
Convert a Map to an Array, List or Set in Java
Python Tuple index()
Python Program to Randomly Select an Element From the List
Python Program to Iterate Through Two Lists in Parallel
Python Program to Find the Sum of Natural Numbers
Python Program to Find Armstrong Number in an Interval
Python Dictionary keys()
Python abs()
Python List clear()
Python Deep Learning - Valentino Zocca & Gianmario Spacagna & Daniel Slater & Peter Roelants
Python Set difference_update()