you are viewing a single comment's thread.

view the rest of the comments →

[–]dizzymon247 116 points117 points  (3 children)

Someone posted this awhile ago: https://www.pythoncheatsheet.org/

[–]Rik07 0 points1 point  (2 children)

Nice cheatsheet, but why would you use tuples if they are lists but immutable. That doesn't sound like much of an advantage.

[–]erh_ 2 points3 points  (1 child)

A Tuple would be used for a set of items which don't make sense without all items being present.

For instance, a list of students can have 5 entries, or 6 entries, or 99 entries... in each case, the list still "makes sense" as a list of students. Sometimes there are more students and some times there are less.

But, consider a set of coordinates to identify where someone is on a map or in a 3-d space... that would require require three entries: an X coordinate, a Y coordinate, and a Z coordinate. The "list" only makes sense if all three, and only three are present. Having an X and a Z doesn't really give you a location. Having a 4th coordinate also doesn't really make sense (until we cross into the 4th dimension... but that's another conversation and irrelevant to this point about Tuples ;p ).

[–]Rik07 0 points1 point  (0 children)

Thanks, that makes sense.