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 Read a File Line by Line Into a List
Python all()
Python Program to Convert Two Lists Into a Dictionary
Python issubclass()
Java Program to Implement the Binary Counting Method to Generate Subsets of a Set
Python Program to Sort a Dictionary by Value
Python Dictionary popitem()
Python Set update()
Intelligent Projects Using Python - Santanu Pattanayak
Python Program to Count the Number of Occurrence of a Character in String
Python Global, Local and Nonlocal variables
Python String format()
Python Set difference_update()
Python Dictionary items()
Python eval()
Python Type Conversion and Type Casting
Python Set discard()
Python isinstance()
Python break and continue
Python Data Structures and Algorithms - Benjamin Baka
Python Program to Concatenate Two Lists
Python Modules
Python String casefold()
Python Generators
Python strftime()
Python String translate()
Python Program to Remove Punctuations From a String
Python String isdigit()
Python abs()
Python List count()
Python Program to Iterate Over Dictionaries Using for Loop
Python Object Oriented Programming