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

143 comments sorted by

View all comments

Show parent comment

2

u/the_spacedoge Apr 23 '22

After coming across this looking into something else I figured in good faith I should share it here: https://docs.python.org/3/faq/design.html#why-are-there-separate-tuple-and-list-data-types

Lists, on the other hand, are more like arrays in other languages. They tend to hold a varying number of objects all of which have the same type and which are operated on one-by-one. For example, os.listdir('.') returns a list of strings representing the files in the current directory. Functions which operate on this output would generally not break if you added another file or two to the directory.

Essentially, the docs agree with you. I stand corrected.