Get startedGet started for free

Create, index, and slice a tuple

You've seen that one of the major differences between a tuple and other data structures, such as a vector is the immutability of the tuple. The creation of a tuple is very similar to that of a vector, and indexing and slicing will also be familiar to you, using the square bracket notation.

In this exercise, you will create, index, and slice a tuple that you will call emergency_information. This tuple should contain the three fields that you identified in the previous question as good data to store in a tuple.

To create a tuple, remember that you need to use parentheses () to contain the values you wish to store in the tuple.

To index and slice a tuple, use the square bracket [] notation after the name of the tuple. Indexing starts at 1 for the first element in Julia.

This exercise is part of the course

Intermediate Julia

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Create a tuple containing the emergency information
emergency_information = (____, ____, ____)
Edit and Run Code