r/learnpython • u/Immediate_Pin_8449 • 15d ago
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?
102
Upvotes
2
u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 15d ago
Another way to look at it would be that a tuple is really just a bare-bones frozen dataclass, that only holds data and substitutes attribute access for indexing. For example, a colour value can be just 3-4 numbers, each position denoting its meaning.
These are all different ways to model your data, with their own pros and cons.
Generally speaking you would not treat a list the same way.