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






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.