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
1
u/eplaut_ Mar 27 '23
I'm using tuples as pairs (or triples, etc...) which contains a whole like in selenium you want an element of
(By.CLASS_NAME, "main-table")or when you want them to be part of sets or dictionary's keys (as lists are not hashable)If my data is constant, I prefer it to be immutable rather than a plain list. Namedtuple is even better.