Python Set update() Method
Updates a set, adding the unique items in the other set or iterable to the source set.
Syntax
Python
Copy Code
set.update(iterable)
Parameters
Parameter | Description |
---|---|
iterable |
Required. An iterable object containing the items that should be added to the given set if they don't already exist. |
Example
Python
Copy Code
desktopComponents = {'memory', 'processor', 'hard drive'} laptopComponents = {'memory', 'processor', 'SSD', 'camera', 'keyboard'} desktopComponents.update(laptopComponents) print(desktopComponents)
Output
{'processor', 'hard drive', 'SSD', 'memory', 'keyboard', 'camera'}