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 Variables, Constants and Literals
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python Program to Sort Words in Alphabetic Order
Python Program to Get the Last Element of the List
Python Program to Make a Simple Calculator
Python list()
How to get current date and time in Python?
Building Chatbots with Python Using Natural Language Processing and Machine Learning - Sumit Raj
Python Set issubset()
Python Program to Display Calendar
Python bytearray()
Python Program to Print Colored Text to the Terminal
Python Decorators
Python Data Structures and Algorithms - Benjamin Baka
Python Dictionary keys()
Python Program to Find Factorial of Number Using Recursion
Python Matrices and NumPy Arrays
Python String rindex()
Python chr()
Python len()
Deep Learning in Python - LazyProgrammer
Python Closures
Python Set isdisjoint()
Python Program to Convert Kilometers to Miles
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python Program to Find the Size (Resolution) of a Image
Python String rsplit()
Python Shallow Copy and Deep Copy
Python String split()
Python slice()