Tuple
A tuple (pronounced "tuh-pull") is a data structure that stores a specific number of elements. These elements may include integers, characters, strings, or other data types.
Mathematics
The term "tuple" originates from math, rather than computer science. A math tuple may be defined as an "n-tuple," where "n" is the number of values the tuple contains. In mathematical expressions, tuples are represented by comma-delimited lists within parentheses. The following example is a "4-tuple," which has four values.
(3, 7, 13, 17)
Tuples serve a variety of purposes in mathematics. They are commonly used to represent a set of related values, such as prime numbers or mathematical sequences. A tuple can also display a range of input or output values for a function.
Computer Science
In computer programming, tuples provide an efficient way to store multiple values. Since they are static and cannot be modified, tuples generally require less memory than arrays. They are also flexible since they can store multiple data types. The following example is a "5-tuple," or a tuple that contains five values.
(11, 2020.07, "techterms", "C", -1000)
The "pentuple" above contains a positive integer (11), floating point number (2020.07), string (techterms), character (C), and a negative integer (-1000).
Tuples are an effective way to store data in computer programs, but not all programming languages support them. For example, Python and Java support tuples, but PHP and Ruby do not. If a language does not support tuples, an immutable array — one that cannot be modified — is the closest alternative.