Python Set copy method with Example – Python Tutorial

1 month ago Lalit Bhagtani 0

In this tutorial, we will learn about python set copy method.
Python Set Copy

copy method :

This method returns a shallow copy of another set. It create a new set, which contains all the element of a set on which copy() method is called and returned it.

Syntax : < Set Object >.copy( ) 


# create set object and assign it to variable s s = {1,2,3,4,5} # print all elements of set s print(s) # create a copy of set s and assign it to variable s1 s1 = s.copy() # print all elements of set s1 print(s1)

References :-

  1. copy method Docs

That’s all for Python Set copy method. If you liked it, please share your thoughts in comments section and share it with others too.