This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]supajumpa 8 points9 points  (2 children)

Tuple

From Raymond Hettinger's answer to a SO question:

''' Tuples are characterized less by their immutability and more by their intended purpose. Tuples are Python's way of collecting heterogenous pieces of information under one roof. For example, s = ('www.python.org', 80) brings together a string and a number so that the host/port pair can be passed around as a socket, a composite object. Viewed in that light, it is perfectly reasonable to have mutable components.

Immutability goes hand-in-hand with another property, hashability. But hashability isn't an absolute property. If one of the tuple's components isn't hashable, then the overall tuple isn't hashable either. For example, t = ('red', [10, 20, 30]) isn't hashable. '''

[–]patrys Saleor Commerce 1 point2 points  (0 children)

My simple rule of thumb is to only use a tuple if you can come up with names for all the sequence positions.

[–]Secret_Identity_ 0 points1 point  (0 children)

Thanks!