Tuple is a composite data type that groups a fixed number of values in order.

Unlike a struct or record, a tuple usually identifies its fields by position rather than by name.

For example, in Python:

point = (10, 20)
x = point[0]
y = point[1]

Tuples are useful for:

  • Returning multiple values
  • Representing small fixed-size groups
  • Pairing related values
  • Pattern matching

Tuples are best when the meaning of each position is obvious. If the values need meaningful field names, a struct, record, class, or dictionary may be clearer.

Anki

id: tuple-definition deck: Computer Science::Data Types tags: data-types tuple

Q: What is a tuple? A: A tuple is a composite data type that groups a fixed number of values in order.

id: tuple-vs-struct deck: Computer Science::Data Types tags: data-types tuple struct

Q: How does a tuple differ from a struct? A: A tuple usually identifies fields by position, while a struct identifies fields by name.