Tuples

A tuple is a fixed-sized group of values separated by commas and optionally surrounded by parentheses ( ). The type of these values can be the same, but it doesn't have to; a tuple can contain values of different types, unlike arrays. A tuple is a heterogeneous container, whereas an array is a homogeneous container. The type of a tuple is just a tuple of the types of the values it contains. So, in this sense, a tuple is very much the counterpart of an array in Julia. Also, changing a value in a tuple is not allowed; tuples are immutable.

In Chapter 2, Variables, Types, and Operations, we saw fast assignment, which is made possible by tuples:

// code in Chapter 5\tuples.jl:
a, b, c, d = 1, 22.0, "World", 'x'

This expression assigns a value ...

Get Julia: High Performance Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.