In this tutorial, we will look at how to convert a tuple to a set in Python with the help of some examples.
Why convert a tuple to a set?
A tuple is a built-in data structure in Python used to store an ordered collection of items. A set, on the other hand, is used to store a collection of objects but it does not preserve any order. Also, a set stores only unique items.
The following are some of the common use-cases when you want to convert a tuple to a set.
- To use the tuple as a set and perform some set operations.
- To remove duplicates from the tuple.
Note that you lose the inherent order in the tuple after conversion to a set (since sets are unordered collections).
How to convert a tuple to a set?

You can use the Python built-in set()
function to convert a tuple to a set. Pass the tuple as an argument to the function. It returns a set resulting from the elements of the tuple.
Highlighted programs for you
Flatiron School
Flatiron School
University of Maryland Global Campus
University of Maryland Global Campus
Creighton University
Creighton University
Let’s look at an example.
# create a tuple t = (2, 5, 1, 3) # create set from tuple s = set(t) # display the set and its type print(s) print(type(s))
Output:
{1, 2, 3, 5} <class 'set'>
Here we create a set from the tuple t
above. You can see that the set contains all the elements from the tuple. Also, note that the inherent order of the elements in the tuple is not preserved in the set.
What if your tuple has duplicate elements? Let’s find out.
# create a tuple t = (2, 5, 5, 1, 3) # create set from tuple s = set(t) # display the set and its type print(s) print(type(s))
Output:
{1, 2, 3, 5} <class 'set'>
The resulting set contains only the distinct elements from the tuple.
Using sets to remove duplicate elements in a tuple or a list is a very common use case in Python.
You might also be interested in –
- Convert Tuple to a String in Python
- Convert Tuple to a String in Python
- Python – Convert Tuple to a String
Subscribe to our newsletter for more informative guides and tutorials.
We do not spam and you can opt out any time.