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 *args and **kwargs
Python for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel
Python callable()
Python set()
Python Program to Add Two Matrices
Python float()
Python Program to Split a List Into Evenly Sized Chunks
Python Program to Convert String to Datetime
Python Program to Check if a Key is Already Present in a Dictionary
Python hash()
Python Program to Illustrate Different Set Operations
Python String isalnum()
Python Program to Differentiate Between type() and isinstance()
Python any()
Python oct()
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Intelligent Projects Using Python - Santanu Pattanayak
Machine Learning with Python for everyone - Mark E.Fenner
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Python Data Structures and Algorithms - Benjamin Baka
Python String splitlines()
Python Program to Check Leap Year
Deep Learning with Python - Francois Chollet
Python dict()
Python isinstance()
Python Set discard()
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python sleep()
Python String join()
Python List
Java Program to Implement Dijkstra’s Algorithm using Set
Python Type Conversion and Type Casting