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

Show parent comments

25

u/hidazfx hlafaille Mar 27 '23

Another one that people don't realize is actually a tuple is enumerate() when using a for loop. enumerate() lets you access the position and the actual value at each iteration.

9

u/[deleted] Mar 27 '23

Doesn't enumerate return an Enumerate object, rather than a tuple ?

9

u/hidazfx hlafaille Mar 27 '23

Never mind, I am wrong! Thank you for correcting me lol.

4

u/[deleted] Mar 27 '23

Heh no worries. It's use case is pretty similar to tuple :)