What's the difference between lists and tuples?
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
In Python, lists and tuples are both sequence data types that can store a collection of items. Each item stored in a list or a tuple can be of any data type. Despite their similarities, there are several key differences which make each type suitable for specific tasks.
Understanding Lists
Lists are mutable sequences, typically used to store collections of homogeneous items (although they can store heterogeneous items as well):
Mutability is a key feature of lists, meaning you can modify them by adding, removing, or changing items after their creation.
Lists also support a number of methods that allow for sophisticated handling, such as append(), remove(), pop(), reverse(), and sort(), among others.
Understanding Tuples
Tuples are immutable sequences, typically used to store collections of heterogeneous data:
Immutability of tuples means that once a tuple is created, its contents cannot be changed, which gives tuples certain advantages:
- Tuples can be used as keys in dictionaries or elements of sets, whereas lists cannot, because keys require immutability for consistent hash values.
- Tuples can be safer in concurrency scenarios because they cannot be modified unexpectedly.
- Generally, tuples require slightly less memory and have faster processing compared to lists.
You cannot add or remove items from a tuple, nor can you alter the items. However, you can take portions of existing tuples to create new tuples:
When to Use List vs Tuple
- List: Use a list if you have a collection of data that will be modified. Lists are more common for tasks where items are added, removed, or changed.
- Tuple: Use a tuple for heterogeneous data collections or data that is intended not to change. Tuples are ideal for storing data that should remain write-protected, such as configuration data.
Performance Considerations
Tuples have a slightly smaller memory footprint and performance than lists, which makes them slightly faster for some operations, such as iteration or as dictionary keys.
Summary Table
Here's a quick reference table that summarizes the main differences between lists and tuples:
| Feature | List | Tuple |
| Type | Mutable | Immutable |
| Syntax | [] | () |
| Memory Usage | Higher | Lower |
| Methods | Numerous (add, remove, sort, etc.) | Fewer (count, index) |
| Suitable Use | Data that changes | Data that does not change |
| Example Use | Data collection processing | Fixed data records, access settings |
Conclusion
Choosing between a list and a tuple depends largely on the situation and requirement of data manipulation. If the data is not going to change and will be used in hashed collections such as dictionaries or sets, a tuple is the preferable choice. For data that is dynamic and expected to change, a list offers the flexibility required. Understanding these differences will help in making effective use of these data structures in Python programming.
Related reading
- What's the difference between lists and tuples?
- What's the difference between lists enclosed by square brackets and parentheses in Python?
- what's the difference between list.sort and stdsort?
- What's the difference between MemoryCache.Add and MemoryCache.Set?
- What''s the difference between MySQLdb, mysqlclient and MySQL connector/Python?
- What''s the difference between MySQLdb, mysqlclient and MySQL connector/Python?
- What's the difference between Minimmum Spanning Tree and Travelling Salesman Problems
- What's the difference between SortedList and SortedDictionary?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.