-1

I frequently see the use of tuples, in contrast to lists, which are mutable. As an intermediate programmer in high school, I am still confused as to the usefulness of tuples.

Are there any other reasons to use them besides their immutability (which is the major response I see to this question)? I know lists can be changed, but is that really such a big problem when programming, other than 'accidents' that might change a list you don't want changed?

Another reason I see, like in this post -- https://stackoverflow.com/questions/30518013/is-there-a-difference-between-a-list-and-a-tuple -- is that you can imagine them different conceptually, such as by imagining them as coordinates, rather than an array of numbers. But this isn't really a function, but a practice that arose because of the freedom for an unchanging structure that tuples supposedly give.

What I'm asking is there a need to have defined a totally new data structure that doesn't really serve a new purpose in my opinion. Thanks! hope this question isn't too dumb :\

Johnyy
  • 1
  • Guarding against "accidents" is actually quite a major feat. Also, mutable types like `list` can't be put into `set` or used as keys for a `dict`. – Stef Feb 09 '23 at 12:40
  • Related: [Difference between list and tuple?](https://stackoverflow.com/questions/9969649/difference-between-list-and-tuple-minus-immutability-in-python?rq=1) and [What's the difference between lists and tuples?](https://stackoverflow.com/questions/626759/whats-the-difference-between-lists-and-tuples) – Stef Feb 09 '23 at 12:47
  • I was not aware that lists could not do that, thank you! – Johnyy Feb 09 '23 at 15:28
  • Note also in python there are `set` and `frozenset`. The distinction between the two is more or less the same as the distinction between `list` and `tuple`. – Stef Feb 09 '23 at 15:51

1 Answers1

0
  1. Tuples are immutable
  2. Tuples can describe things like coordinates and dimensionality better than list
  3. To guard against accidents
  4. Tuples can be put into set and used as keys for dict
Johnyy
  • 1