Python Set symmetric_difference() Method

Returns a new set that contains all the items from both sets except items that are present in both sets.

Syntax

Python
set.symmetric_difference(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'}
difference = desktopComponents.symmetric_difference(laptopComponents)
print(difference)

Output

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