Python Set copy() Method
Returns a copy of the set. The original set and the new set are now independent of each other.
Syntax
Python
Copy Code
set.copy()
Example
Python
Copy Code
desktopComponents = {'memory', 'processor', 'SSD'} laptopComponents = desktopComponents.copy() laptopComponents.add('keyboard') print(f'Desktop Components: {desktopComponents}') print(f'Laptop Components: {laptopComponents}')
Output
Desktop Components: {'SSD', 'processor', 'memory'} Laptop Components: {'SSD', 'processor', 'keyboard', 'memory'}