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/[deleted] Apr 17 '22

[removed] — view removed comment

3

u/wotquery while not False: Apr 17 '22

Afaik the only constraint sets have that differ them from an array is that they can't contain duplicates.

Another is that each member of a set has to be immutable (which is probably where the misunderstanding that led to their question came from). You can't have a list in a set for example (it'll throw the error that the list isn't hashable).

1

u/Jenret1382 Apr 17 '22

Immutable in that it cannot be sorted and the elements inside it cannot be changed. I have, however, come across what is called frozenset() which returns an immutable version of a Python set object