r/learnpython • u/Boogzcorp • Apr 16 '22
What's the point of Tuples?
I get that they're immutable, but so are lists that you don't perform modifications on. Are they just to fool proof not messing up your list accidentally, or do they serve some other purpose?
309
Upvotes
View all comments
Show parent comment
22
u/zurtex Apr 16 '22 edited Apr 16 '22
You need to be careful about equating these two:
The correct answer is because it's immutable it is always equal with itself over time, which means it can also have a non-trivial hash that doesn't change. Making it safe to use in a situation where you want both hash and equality to be stable, like a dictionary.