Python Set update() Method

Updates a set, adding the unique items in the other set or iterable to the source set.

Syntax

Python
set.update(iterable)

Parameters

ParameterDescription
iterable Required. An iterable object containing the items that should be added to the given set if they don't already exist.

Example

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

Output

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