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 Convert Decimal to Binary Using Recursion
Python Program to Find Factorial of Number Using Recursion
Python List sort()
Python Data Types
Python Keywords and Identifiers
Python Operators
Python help()
Python max()
Python Program to Add Two Numbers
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Python Deep Learning - Valentino Zocca & Gianmario Spacagna & Daniel Slater & Peter Roelants
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python File I/O Operation
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python divmod()
Python zip()
Python Program to Get the Class Name of an Instance
Python list()
Python Program to Print all Prime Numbers in an Interval
Convert a Map to an Array, List or Set in Java
Python Set remove()
Python List remove()
Python String zfill()
Python String isdecimal()
Python int()
Python Program to Display the multiplication Table
Python Program to Create a Long Multiline String
Python Program to Check Leap Year
Python Program to Check if a Key is Already Present in a Dictionary
Python Program to Check if a Number is Positive, Negative or 0
Python float()