Method signature:
copy()
Method overview:
The copy() method returns a copy of the set. The copy returned contains shallow copy of the elements.
i.e., A new set object is created and the elements are copied from the source set.
The elements are not created afresh.They are just referred.
Return Value:
A new set object containing shallow copy of the elements from the original set.
Example:
# Example Python program that copies the elements of # Create a set of jobs for printing # Copy the jobs into a backup set print("Newly created set using copy():") print("Ids of the sets:") # While the backup set is newly created the elements are not elem = next(iter(backupJobs)) |
Output:
Newly created set using copy(): {'Job2', 'Job5', 'Job1', 'Job3', 'Job4'} Ids of the sets: 4308111584 4308110240 Ids of first elements from both the sets: 4308014000 4308014000 |