Python provides several built-in data structures to store collections of elements, including lists, tuples, and sets. While lists are commonly used, tuples and sets have specific use cases. Tuples are ordered collections of immutable elements, while sets are unordered collections of unique elements.
I will explain the differences between Python sets and tuples in this tutorial with some practical examples.
What are Tuples in Python?
A tuple is a collection of Python objects, much like a list. The sequence of values stored in a tuple can be of any type, and integers index them. Tuples are immutable, meaning that once created, their elements cannot be changed. Tuples are defined using parentheses () or by simply separating elements with commas.
Example of creating a tuple:
my_tuple = (1, 2, 3, 'apple', 'banana')Tuples support indexing and slicing, just like lists:
my_tuple = (1, 2, 3, 'apple', 'banana')
print(my_tuple[0]) # Output: 1
print(my_tuple[1:4]) # Output: (2, 3, 'apple')Here is the exact output in the screenshot below:

Check out How to Use Python Type Hint Tuples for More Robust Code?
What are Sets in Python?
Sets are unordered collections of unique elements. They are defined using curly braces {} or the set() constructor. The major difference between sets and lists or tuples is that sets cannot have multiple occurrences of the same element and store unordered values.
Example of creating a set:
my_set = {1, 2, 3, 'apple', 'banana'}Since sets are unordered, you cannot access elements using indexing or slicing. However, sets provide powerful methods for mathematical set operations like union, intersection, and difference.
set1 = {1, 2, 3}
set2 = {3, 4, 5}
print(set1.union(set2)) # Output: {1, 2, 3, 4, 5}
print(set1.intersection(set2)) # Output: {3}
print(set1.difference(set2)) # Output: {1, 2}Here is the exact output in the screenshot below:

Read How to Print a Tuple in Python?
Key Differences between Sets and Tuples
- Mutability:
- Tuples are immutable, meaning their elements cannot be changed once created.
- Sets are mutable, allowing addition or removal of elements.
- Ordering:
- Tuples maintain the order of elements as defined.
- Sets are unordered and do not preserve the order of elements.
- Duplicates:
- Tuples can contain duplicate elements.
- Sets cannot contain duplicate elements; they only store unique values.
- Indexing and Slicing:
- Tuples supports indexing and slicing to access elements according to their position.
- Sets do not support indexing or slicing since they are unordered.
- Mathematical Set Operations:
- Sets provide built-in methods for mathematical set operations like union, intersection, and difference.
- Tuples do not have built-in support for set operations.
Read How to Check if a Tuple is Empty in Python?
When to Use Tuples vs Sets
The purpose of a tuple is to represent an entity without using a class. The purpose of a set is to hold multiple unique items. Let me explain when to use tuple vs sets in Python.
Use tuples when:
- You have a fixed collection of elements that shouldn’t change.
- The order of elements is important and needs to be preserved.
- You want to use the collection as a key in a dictionary.
Use sets when:
- You need to store a collection of unique elements.
- The order of elements is not important.
- You want to perform mathematical set operations like union, intersection, or difference.
Check out How to Unpack a Tuple in Python?
Python Set vs Tuple: Summary
Here is a summary of the differences between Python set vs tuple.
| Feature | Tuple | Set |
|---|---|---|
| Mutability | Immutable | Mutable |
| Ordering | Ordered | Unordered |
| Duplicates | Allowed | Not Allowed |
| Indexing/Slicing | Supported | Not Supported |
| Set Operations | Not Supported | Supported |
Conclusion
Tuples are immutable and ordered, making them suitable for representing fixed collections where element order matters. Sets, on the other hand, are mutable and unordered, ideal for storing unique elements and performing set operations. In this tutorial, I explained when to use tuple vs set in Python with some real examples.
You may also like:
- How to Reverse a Tuple in Python?
- How to Pass a Tuple as an Argument to a Function in Python?
- How to Split a Tuple in Python?

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.