Home »
Python
Python Set copy() Method with Example
Python Set copy() Method: Here, we are going to learn how to copy a complete set using copy() method in Python?
Submitted by IncludeHelp, on November 27, 2019
Set copy() Method
copy() method is used to copy the set, it returns a set that contains all elements of this set.
Syntax:
set_name.copy()
Parameter(s):
- It does not accept any parameter.
Return value:
The return type of this method is <class 'set'>, it returns a set contains the copy of this set.
Example:
# Python Set copy() Method with Example
# declaring a set
cities = {"New Delhi", "Mumbai", "Indore", "Gwalior"}
# creating another set by using
# copy() method
x = cities.copy()
# printing both sets
print("cities: ", cities)
print("x: ", x)
Output
cities: {'New Delhi', 'Mumbai', 'Indore', 'Gwalior'}
x: {'New Delhi', 'Mumbai', 'Indore', 'Gwalior'}
TOP Interview Coding Problems/Challenges