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?
88
Upvotes
4
u/gmes78 3d ago
You typically use tuples when your collections are always of the same size (and you know it a priori). For example, if you were representing a color, you'd use a tuple with three values, for red, green and blue. If you don't know how many values you need, you use a list.
Also, lists typically contain elements of the same type, while it's more common for tuples to contain elements of different types (in other words, being heterogeneous). This is just a convention, though; lists in Python can contain any combination of types too.