Python Set union() Method
Returns the union of two or more sets.
Syntax
Python
Copy Code
set.union(set1 [, set2, ...])
Parameters
Parameter | Description |
---|---|
set1 [, set2, ...] |
Required. One or more sets that will be used to create a new set based on the union of the sets' items. |
Example
Python
Copy Code
desktopComponents = {'memory', 'processor', 'hard drive'} laptopComponents = {'memory', 'processor', 'SSD', 'camera', 'keyboard'} greatComputer = desktopComponents.union(laptopComponents) print(greatComputer)
Output
{'camera', 'memory', 'hard drive', 'keyboard', 'processor', 'SSD'}