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/cdcformatc Mar 27 '23 edited Mar 27 '23

Any type of coordinate, like (Latitude, Longitude), or (X, Y) on a Cartesian plane. Add in height or Z coordinate and you have a 3-tuple. pretty much any video game you have ever played is going to track the player and enemy locations with coordinate tuples.

I tangentially work with cameras and their real world location is described by lat, long, height, and their rotation which you could think of as a compass heading, and they also have field of view. So the physical location of the camera is described as a 5-tuple and we draw a cone on a map to show what the camera is pointed at. Theoretically we also have pitch and roll in addition to the rotation/yaw but we don't do anything with that info right now, but i could imagine that would be useful for drone flight and video information.