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
138
u/carcigenicate Carcigenicate Mar 27 '23 edited Mar 30 '23
The simplest example would likely be just "returning two values from a function":
,is used to create a tuple. The tuple is being used here to wrap two integers so they can be returned together. Just being able to group data is often useful, and tuples are a straightforward way to do that.