r/learnpython • • 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

64 comments sorted by

View all comments

1

u/Sigg3net Mar 27 '23

Whenever I have items that shouldn't change, it's a tuple. Lists invite appending to and popping.

You can also use tuples inside list comprehensions as "keys"', e.g.:

ages = [ age for (name, age, job) in employees ]