Python Set symmetric_difference_update() Method

Removes the items from the given set that are present in both sets, and inserts the items that are not present in both sets.

Syntax

Python
set.symmetric_difference_update(otherSet)

Parameters

ParameterDescription
otherSet Required. The set whose elements will be compared with the given set.

Example

Python
desktopComponents = {'memory', 'processor', 'hard drive'}
laptopComponents = {'memory', 'processor', 'SSD', 'camera', 'keyboard'}
desktopComponents.symmetric_difference_update(laptopComponents)
print(desktopComponents)

Output

{'SSD', 'keyboard', 'camera', 'hard drive'}