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 int()
Python List reverse()
Python Custom Exceptions
Python float()
Python Operator Overloading
Python Program to Check If Two Strings are Anagram
Python Program to Swap Two Variables
Python Program to Iterate Through Two Lists in Parallel
Python bytes()
Python timestamp to datetime and vice-versa
How to Get Started With Python?
Python Decorators
Machine Learning with Python for everyone - Mark E.Fenner
Python Dictionary copy()
Python strftime()
Python Dictionary
Python for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel
Python break and continue
Python Set pop()
Python enumerate()
Python List count()
Python Tuple
Python Program to Find Sum of Natural Numbers Using Recursion
Python File I/O Operation
Python print()
Python Program to Count the Number of Each Vowel
Python Directory and Files Management
Python Program to Print all Prime Numbers in an Interval
Python Program to Create Pyramid Patterns
Python Program to Print Colored Text to the Terminal
Python Dictionary items()
Python Deep Learning Cookbook - Indra den Bakker