ComeçarComece de graça

Create a NamedTuple for a person

In the previous example, we created a tuple to store the emergency information of a particular person. But when creating this tuple, we had to remember that the first element was the birth date, the second was the birth location, and the third was a blood type. In this case, with only three fields, this isn't too much to remember. But when we start to use larger tuples, it can be useful to name each field, reminding us what the value represents and giving an easy way to access that value.

In this example you will create the same tuple as in the previous question, but this time with named attached to each field.

Este exercício faz parte do curso

Intermediate Julia

Ver curso

Instruções do exercício

  • Create a NamedTuple called emergency_information that names the three fields:
    • birthdate equal to 1990-05-24
    • birthlocation equal to Los Angeles
    • bloodtype equal to O+
  • Print each field of the NamedTuple on a new line, accessing each field using its name.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# Create a NamedTuple with the names and values in the instructions
emergency_information = (____)
# Print the birthdate, birthlocation and bloodtype of the tuple
println(emergency_information.____)
println(emergency_information.____)
println(emergency_information.____)
Editar e executar o código