Predict the Unpacking Output
Intermediate · Predict the output · from Python Unpacking: Starred Expressions, Swapping, and Destructuring
From the lesson: Python Unpacking: Starred Expressions, Swapping, and Destructuring
Imagine you order a package online that contains three items: a book, headphones, and a phone case. When the box arrives, you open it and put each item where it belongs. The book goes on the shelf, headphones go on the desk, and the case goes on your phone.
Read the lessonWhat does this code print? Think about what the star captures and what type it becomes.
a, *b, c = [1, 2, 3, 4, 5, 6]
print(a)
print(b)
print(c)Write three print() statements that produce the exact same output.
# Predict the output and write the matching print statements
print("?")
print("?")
print("?")
More Unpacking exercises
- Unpack a CoordinateBeginner
- Swap Two VariablesBeginner
- Head and Tail with StarIntermediate
- Unpack Student RecordsAdvanced
All Python exercises · 50 practice problems · Data Structures quiz