A tuple is an ordered collection written with parentheses, useful when one record combines values of different types. Unlike an array, a tuple is immutable: you can read its values, but you cannot replace them. section 4.9 section 4.13
Use tuples when each position has a distinct meaning and the record should remain unchanged:
- Write a pizza record as ("hawaiian", 'S', 10.5), combining a String, Char, and Float64. section 4.9
- Inspect its precise element types with typeof; Julia reports Tuple{String, Char, Float64}. section 4.9
- Read values by index, iterate with a for loop, or pass numeric tuples to functions such as sum, median, and mean. section 4.9
- Store multiple records in an array of tuples, then extract a field with a helper such as name(pizza) = pizza[1]. section 4.9
Pizza sales records
julia> sales = [("hawaiian", 'S', 10.5), ("sicilian", 'S', 12.25), ("hawaiian", 'L', 16.5)] julia> sales[1] ("hawaiian", 'S', 10.5) Each tuple represents one sale, while the surrounding array holds the collection. This arrangement preserves the distinct types of the pizza name, size, and price. A tuple can be read but not modified: pza[1] = "pepperoni" raises a setindex! error. section 4.9
pizza_tuple = ("hawaiian", 'S', 10.5)
View the compact pizza tuple literal used to introduce mixed-type records. section 4.9














