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 Directory and Files Management
Python String swapcase()
Python Global Keyword
Python Program to Convert Decimal to Binary Using Recursion
Python Program to Make a Flattened List from Nested List
Python Program to Solve Quadratic Equation
Python List clear()
Python String endswith()
Python oct()
Python Program to Get Line Count of a File
Python Dictionary clear()
Python Program to Capitalize the First Character of a String
Deep Learning from Scratch - Building with Python form First Principles - Seth Weidman
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python Program to Append to a File
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python Iterators
Python Set clear()
Machine Learning with Python for everyone - Mark E.Fenner
Python Package
Python Program to Make a Simple Calculator
Python round()
Python Multiple Inheritance
Python if...else Statement
Python frozenset()
Building Chatbots with Python Using Natural Language Processing and Machine Learning - Sumit Raj
Python String maketrans()
Java Program to Implement Dijkstra’s Algorithm using Set
Python Dictionary popitem()
Python frozenset()
Python String isidentifier()
Python Custom Exceptions