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
set.copy()

Example

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