Python List vs Tuple: Differences and When to Use Each
[], while a tuple is a fixed (immutable) sequence written with (); pick a list when the contents will change and a tuple when they should stay constant.Lists and tuples both hold ordered items that you read by index, loop over and slice, so beginners often wonder why Python has both. The difference is one rule: you can add, remove and replace items in a list, but a tuple is frozen the moment it is created.
That single rule has useful side effects. Because a tuple cannot change, Python can use it as a dictionary key, share it safely between functions and store it a little more compactly. Because a list can change, it is the right tool for anything you build up over time, such as a shopping cart.
The example below shows the difference in two lines.
sizes_list = ["S", "M", "L"]
sizes_tuple = ("S", "M", "L")
sizes_list[0] = "XS"
print(sizes_list)
print(sizes_tuple[0])List vs tuple comparison table
| Aspect | List | Tuple |
|---|---|---|
| Syntax | [1, 2, 3] | (1, 2, 3) or 1, 2, 3 |
| Mutable? | Yes: items can be added, removed and replaced | No: fixed after creation |
| Methods | Many, e.g. append(), remove(), sort() | Only count() and index() |
| Hashable (dictionary key or set member)? | No | Yes, if every item inside is hashable |
| Typical content | Many items of the same kind (a list of prices) | A few fields of one record (a latitude and longitude pair) |
| Speed and memory | Slightly more memory because it can grow | Slightly smaller and quicker to create |
| One-item syntax | [5] | (5,) (the trailing comma is required) |
When to use a list
Use a list when the collection is going to change while your program runs, or when you do not know the number of items in advance.
- You collect values in a loop with append().
- You need to sort, reverse, insert or remove items.
- All the items mean the same thing (every element is a score, a name or a product).
A list is the default choice when you are unsure. You can always convert it later with tuple(my_list).
When to use a tuple
Use a tuple when the values belong together as one fixed record, or when you need something hashable.
- Returning several values from a function (
return name, ageactually returns a tuple). See tuple unpacking. - Dictionary keys such as
(row, column)for a grid. - Constants that should never be modified by accident, like
WEEKEND = ("Sat", "Sun").
The immutability is a signal to other readers: this data is not meant to change.
Does a tuple make its contents immutable?
A tuple fixes which objects it holds, not what those objects can do. If a tuple contains a list, you cannot replace that list with another object, but you can still change the list itself. This surprises many learners, and it is explained further in mutable vs immutable.
Examples you can run
Press Run, then edit the code and run it again.
Changing a list works, changing a tuple fails
Assigning to an index is allowed on a list and raises a TypeError on a tuple. We catch the error so you can see its message.
scores = [70, 85, 90]
scores[0] = 75
print(scores)
settings = (70, 85, 90)
try:
settings[0] = 75
except TypeError as error:
print(error)Expected output[75, 85, 90]
'tuple' object does not support item assignment
A tuple works as a dictionary key
Tuples are hashable, so they can label a position, while a list cannot.
seats = {(1, 2): "Asha", (1, 3): "Ravi"}
print(seats[(1, 2)])
try:
seats[[1, 4]] = "Meena"
except TypeError as error:
print(error)Expected outputAsha
unhashable type: 'list'
A tuple that contains a list
The tuple still points to the same list, but the list can be modified.
order = ("order-7", ["pen", "book"])
order[1].append("ruler")
print(order)Expected output('order-7', ['pen', 'book', 'ruler'])
Common mistakes
Forgetting the comma in a one-item tuple
✗ Wrong
single = (5)
print(type(single))✓ Right
single = (5,)
print(type(single))Parentheses alone only group an expression. The comma is what makes a tuple, so write (5,).
Trying to append to a tuple
✗ Wrong
coords = (10, 20)
coords.append(30)✓ Right
coords = (10, 20)
coords = coords + (30,)
print(coords)A tuple cannot grow. Convert it to a list, change it, or build a new tuple with +.
Python List vs Tuple: Differences and When to Use Each: questions people ask
Is a tuple faster than a list in Python?
Slightly, for creating and storing small collections, because a tuple has a fixed size. For most programs the difference is too small to matter, so choose based on whether the data should change.
Can I convert a list to a tuple and back?
Yes. tuple(my_list) makes a tuple and list(my_tuple) makes a list. Both create a new object and leave the original untouched.
Why does Python have tuples if lists can do everything?
Tuples guarantee the collection will not change, which makes them hashable, safe to share and clear in intent. Lists trade that guarantee for flexibility.
Keep learning
Step-by-step lessons:
Python ListsPython TuplesPython Data Types
Related:
Python List vs Set: Differences and When to Use EachPython List vs Dictionary: Differences and When to Use EachPython Mutable vs Immutable Objects ExplainedPython Unpacking
More in data types and structures:
Python List vs Set: Differences and When to Use EachPython List vs Dictionary: Differences and When to Use EachPython Mutable vs Immutable Objects Explained See all →