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
Copy Code
set.symmetric_difference(otherSet)
Parameters
Parameter | Description |
---|---|
otherSet |
Required. The set whose elements will be compared with the given set. |
Example
Python
Copy Code
desktopComponents = {'memory', 'processor', 'hard drive'} laptopComponents = {'memory', 'processor', 'SSD', 'camera', 'keyboard'} difference = desktopComponents.symmetric_difference(laptopComponents) print(difference)
Output
{'keyboard', 'camera', 'hard drive', 'SSD'}