×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Python Set symmetric_difference_update() Method (with Examples)

Last Updated : December 11, 2025

Python Set symmetric_difference_update() Method

The symmetric_difference_update() is an inbuilt method of the set class that is used to get the list of all elements which are not common in both sets and update this set (set1) with these elements i.e., it updates this set (set1) by removing the elements which are common in both sets.

Syntax

The following is the syntax of symmetric_difference_update() method:

set1.symmetric_difference_update(set2)

Parameter(s):

The following are the parameter(s):

  • set2 – It represents another set to be compared with this set (set1).

Return Value

The return type of this method is <class 'NoneType'>, it updates this set (set1) by removing the elements which are common in both sets.

Example 1: Use of Set symmetric_difference_update() Method

# declaring the sets
cars_1 = {"Porsche", "Audi", "Lexus"}
cars_2 = {"Porsche", "Mazda", "Lincoln"}

# printing sets before symmetric_difference_update()
print("Before calling symmetric_difference_update()...")
print("cars_1:", cars_1)
print("cars_2:", cars_2)

# symmetric_difference_update() method call
cars_1.symmetric_difference_update(cars_2)

# printing sets after symmetric_difference_update()
print("After calling symmetric_difference_update()...")
print("cars_1:", cars_1)
print("cars_2:", cars_2)

Output

Before calling symmetric_difference_update()...
cars_1: {'Audi', 'Lexus', 'Porsche'}
cars_2: {'Porsche', 'Mazda', 'Lincoln'}
After calling symmetric_difference_update()...
cars_1: {'Mazda', 'Audi', 'Lincoln', 'Lexus'}
cars_2: {'Porsche', 'Mazda', 'Lincoln'}

Example 2: Use of Set symmetric_difference_update() Method

# declaring the sets
x = {"ABC", "PQR", "XYZ"}
y = {"ABC", "PQR", "XYZ"}
z = {"DEF", "MNO", "ABC"}

# printing the results
print("Before calling symmetric_difference_update()...")
print("x:", x)
print("y:", y)
print("z:", z)

# printing the result of 
# symmetric_difference_update()
x.symmetric_difference_update(y)
y.symmetric_difference_update(z)
z.symmetric_difference_update(x)

# printing the results
print("After calling symmetric_difference_update()...")
print("x:", x)
print("y:", y)
print("z:", z)

Output

Before calling symmetric_difference_update()...
x: {'ABC', 'XYZ', 'PQR'}
y: {'ABC', 'XYZ', 'PQR'}
z: {'ABC', 'MNO', 'DEF'}
After calling symmetric_difference_update()...
x: set()y: {'XYZ', 'MNO', 'DEF', 'PQR'}
z: {'ABC', 'MNO', 'DEF'}
Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.