r/learnpython • • Oct 12 '26

Tuples..I don’t get it

Hi crew, I’m a Python newbie and I just learned about the concept of tuples.

We can’t change them.if we want to store we have to start at the index we want + 1.

I just don’t get it. Why wouldn’t we just use lists? When would we ever need this?

100 Upvotes

89 comments sorted by

View all comments

113

u/NerdyWeightLifter Oct 12 '26

Being immutable like that means the underlying data structure can be simpler and more efficient.

Being immutable also makes them useful as keys in dictionaries. Keys in dictionaries can't change once you insert something.

9

u/dusksage23 Oct 13 '26

the dict key thing is the part that really makes it click imo

9

u/NerdyWeightLifter Oct 13 '26

In larger more complex applications, immutability becomes an important guarantee. You have a reference to a list of items in the form of a reference to a tuple, and you can just assume that nothing will change the content of your tuple, because they just can't.

That's the broader case of the dict example.

3

u/fllthdcrb Oct 13 '26

you can just assume that nothing will change the content of your tuple, because they just can't.

To be clear, "content" here means only what objects are in the tuple, not those objects themselves. Example:

l1 = []
l2 = []
t = (l1, l2)
l1 += (1, 2, 3)
l2 += (4, 5, 6)
t  # ([1, 2, 3], [4, 5, 6])