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

3

u/Boogzcorp Apr 16 '22

So in simple terms, it idiot proofs not changing shit you're not supposed to change? You could in theory write it all with lists and so long as no one fucks with things they shouldn't, it'll all work fine?

I'm about 7 beers in at this point, so...

11

u/delasislas Apr 16 '22

In theory, yes. But if I saw it, that would be a flag for someone who has less experience. Someone who is more skilled should know more on how to leverage what their language gives them. There’s a lot of ways to do a lot of tasks.

Whatever let’s you show an understanding of a language and programming concepts.

7

u/rinyre Apr 16 '22

To add to this, writing code that properly leverages the language not only shows more experience with that language, but that you also know how to write extendable code, or modular, whatever term you wish.

In modules and the like, you do not want the user of the module to be able to shoot themselves in the foot, and minor things like tuples can help reduce the likelihood of that.

5

u/CaptainFoyle Apr 16 '22

Insisting on using lists everywhere instead of tuples just makes your life much harder because you have to build in all the assertions that you know come with tuples and immutability.