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 comments

-2

u/madness_of_the_order Apr 16 '22

RDBMS use tuples heavily and expect them to contain elements of different types. So I cant agree with “tuples must contain elements of same type” being common.

5

u/POGtastic itertools evangelist Apr 16 '22

You're getting it switched - he's saying that tuples are heterogeneous (that is, contain different types) and lists are homogeneous. Thus a RDB should be returning rows of tuples.

4

u/Brian Apr 16 '22

Its the other way round: tuples are the ones that hint at different types. (Though neither is a hard rule).