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 String istitle()
Python pow()
Python Custom Exceptions
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python set()
Building Chatbots with Python Using Natural Language Processing and Machine Learning - Sumit Raj
Python String swapcase()
Python pass statement
Converting Between an Array and a Set in Java
Python delattr()
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python List sort()
Python String isspace()
Python Program to Catch Multiple Exceptions in One Line
Python String isalnum()
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Python Program to Append to a File
Python Set intersection()
Python Program to Print Colored Text to the Terminal
Python Program to Get the Class Name of an Instance
Python map()
Python String expandtabs()
Python property()
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python Program to Find HCF or GCD
Python Dictionary clear()
How to get current date and time in Python?
Python len()
Python String isprintable()
Python Type Conversion and Type Casting
Python Set issuperset()
Python Artificial Intelligence Project for Beginners - Joshua Eckroth