Python Set difference_update() Method
Updates the source set by removing the items that exist in both sets.
Syntax
Python
Copy Code
set.difference_update(otherSet)
Parameters
Parameter | Description |
---|---|
otherSet |
Required. The set to compare with the current set. |
Example
Python
Copy Code
desktopComponents = {'memory', 'processor', 'hard drive'} laptopComponents = {'memory', 'processor', 'SSD', 'camera', 'keyboard'} laptopComponents.difference_update(desktopComponents) print(f'Components unique to the laptop computer: {laptopComponents}')
Output
Components unique to the laptop computer: {'SSD', 'camera', 'keyboard'}