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.
This exercise is part of the course
Intermediate Julia
Exercise instructions
- Create a NamedTuple called
emergency_information
that names the three fields:birthdate
equal to1990-05-24
birthlocation
equal toLos Angeles
bloodtype
equal toO+
- Print each field of the NamedTuple on a new line, accessing each field using its name.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# 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.____)