Python Set difference_update() Method

Updates the source set by removing the items that exist in both sets.

Syntax

Python
set.difference_update(otherSet)

Parameters

ParameterDescription
otherSet Required. The set to compare with the current set.

Example

Python
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'}