Python Set copy()
Python Set copy()
method returns a copy of the set.
In this tutorial, we will learn the syntax of set.copy() method and go through some example programs covering copy() method.
Syntax
The syntax of set.copy() is
</>
Copy
set.copy()
The method returns a new set with the elements of the calling set.
Examples
1. Copy a set
In the following program, we will copy a set s
to s_copy
.
Python Program
</>
Copy
s = {'apple', 'banana', 'cherry'}
s_copy = s.copy()
print(s_copy)
Program Output
{'banana', 'cherry', 'apple'}
Conclusion
In this Python Tutorial, we learned about Python set method set.copy(). We have gone through the syntax of copy() method, and its usage with example programs.