r/learnpython • u/Pure-Homework681 • Mar 27 '23
Actually using a tuple
Can someone, please, give me a "real-world" example on the use of a tuple? I'm learning through w3schools. The idea of a tuple sort of makes sense, but I have no idea how it would/could be applied.
147
Upvotes
3
u/B1GTOBACC0 Mar 27 '23
I think some people struggle to understand "why would I use this instead of a list?"
In some cases, the data is only meaningful when it's all together and set in a specific order. For example, I could represent a color with RGB values in a tuple like (245, 35, 173).
On their own, those numbers aren't meaningful. I wouldn't have a reason to sort/reorder the values or iterate over this tuple, but I can't represent a color without all 3 numbers.