Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Tuple basics
10. Tuple unpacking
Tuples in functions


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:


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