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 be; 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 ...

Get Julia 1.0 Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.