Python Tutorial Python Advanced Python References Python Libraries

Python Set - copy() Method



The Python copy() method is used to copy the entire set into a new set.

Syntax

set.copy()

Parameters

No parameter is required.

Return Value

Returns a copy of the specified set.

Example:

In the example below, the set called MySet is copied entirely into a new set called NewSet. To perform this operation the copy() method is used.

MySet = {'Red', 'Blue', 'Green'}
NewSet = MySet.copy()
print(NewSet)

The output of the above code will be:

{'Blue', 'Red', 'Green'}

❮ PPython Set Methods