Book Image

Getting Started with Julia

By : Ivo Balbaert
Book Image

Getting Started with Julia

By: Ivo Balbaert

Overview of this book

Table of Contents (19 chapters)
Getting Started with Julia
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
The Rationale for Julia
Index

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 1, b becomes 22.0, c takes up the value World, and d becomes x.

The expression returns a tuple (1, 22.0,"World",'x'), as the REPL shows as follows:

If we assign this tuple to a variable t1 and ask for its type, we get the following result:

  typeof(t1...