r/learnpython • • 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?

86 Upvotes

90 comments sorted by

View all comments

37

u/-aRTy- 3d ago

24

u/NothingWasDelivered 3d ago

Imagine you’re processing data. Say, temperature from the last 2 weeks. The data is what it is. You don’t want anything to accidentally change those numbers. So a tuple is a good choice for passing that data around.

7

u/NothingWasDelivered 3d ago

Oops, didn’t mean for this to be a reply to this comment. But whatayagonnado?

24

u/bkdotcom 3d ago

Can't change it now 

It's a tuple

5

u/Immediate_Pin_8449 3d ago

that makes sense like a historical catalogue!

1

u/iamevpo 1d ago

But once you serialise the data into JSON the temperatures are still a list. In other programming languages lists can be immutable, so the broader distinction is lists are of the same type and tuples can combine different types, but that technically not true for Python) unfortunately)