Psst! Check what courses we have in our offer, and get them all here to save $727. Tick-tock—this deal ends on 3/21.
Introduction
Tuple basics
10. Tuple unpacking
Tuples in functions
Summary

Instruction

Good job! Now, let's talk about tuple unpacking. Suppose you have the following tuple defined:

user_data = ('John', 'Smith', 29, 1.85, 'British')

Later in your code, you may want to unpack the tuple into multiple variables. You can do it like this:

first_name, last_name, age, height, nationality = user_data

Each variable in the code above will get a single element from the tuple and its respective type:

Exercise

Unpack the train_connection tuple into four variables: from_city, to_city, distance, and price respectively.

Stuck? Here's a hint!

Use the following code:

from_city, to_city, distance, price = train_connection