How to Use Set copy() Method in PythonPython Basics


The copy() method is used to copy a set.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

Car1 = {"Mercedes-Benz", "Rolls-royce", "CADILLAC","Honda","Hyundai","Land Rover"}
print(Car1)
Car2=Car1.copy()
print(Car2)

Output:

{'Honda', 'Land Rover', 'Hyundai', 'CADILLAC', 'Mercedes-Benz', 'Rolls-royce'}
{'Hyundai', 'CADILLAC', 'Land Rover', 'Rolls-royce', 'Mercedes-Benz', 'Honda'}

Syntax

set.copy()

Parameters

The method doesn’t take any parameters.

Return Value

It returns a shallow copy of the set.

© 2024 Learnwithgpt.org, all rights reserved. Privacy Policy | Contact Us