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 to Catch Multiple Exceptions in One Line
Python Program to Convert Celsius To Fahrenheit
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python Program to Safely Create a Nested Directory
Python @property decorator
Python Program to Count the Number of Each Vowel
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python isinstance()
Python List Comprehension
Python Program to Swap Two Variables
Python Operators
Python Program to Check if a Key is Already Present in a Dictionary
Python String istitle()
Python String maketrans()
Python String isnumeric()
Python String strip()
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python Program to Print all Prime Numbers in an Interval
Python Program to Remove Punctuations From a String
Python Program to Get the File Name From the File Path
Python String title()
Python property()
Python List remove()
Python Program to Parse a String to a Float or Int
Python String rsplit()
Python all()
Python Machine Learning - Sebastian Raschka
Python Global Keyword
Python open()
Python min()
Node.js vs Python for Backend Development
Java Program to Implement Dijkstra’s Algorithm using Set