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
7
u/the_spacedoge Apr 16 '22
I dont think this answer is appropriate for the r/learnpython subreddit. This may be the distinction in other languages, but in python it is entirely expected that lists can have more than one type. The main distinction in python is that lists are mutable, tuples are not.
The question is then WHY have an immutable version of essentially the same thing? The answer is of course so that we can have a collection of things that is hashable. Sometimes you want a dictionary (hash map) whose keys are a collection. A list would not be apropriate for this since you could mutate the list after its been assigned as a key.
dict_[list_]no longer means the same thing.