Kom igångKom igång gratis

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.

Den här övningen är en del av kursen

Intermediate Julia

Visa kurs

Interaktiv övning med praktiskt arbete

Testa den här övningen genom att slutföra den här exempelkoden.

# Create a tuple containing the emergency information
emergency_information = (____, ____, ____)
Redigera och kör kod