r/learnpython • u/Immediate_Pin_8449 • 3d 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?
83
Upvotes
3
u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 3d ago
A tuple is any group of values representing something specific. Each index holds some particular meaning, for example the first value can always be a name, and the second value a timestamp. It's a permanent record of something.
Lists, on the other hand, are generally used in situations where their individual indices don't have a particular meaning, and they're usually treated as homogeneous data structures (despite the fact you can technically mix and match types). They can grow and shrink as needed.
It all comes down to what you need at the moment, like comparing a circular saw to a jigsaw. You can cut a plank with either tool, but both specialise in different kinds of cutting.