LearnFrenzy
Sign in Take a free test

Lists · Predict the Output · Question 13

Starred unpacking of a list Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 13 Back to Exercise

What is the output of the following Python program?

main.py
first, *mid, last = [1, 2, 3, 4, 5]
print(first, mid, last)
a, *b = [9]
print(a, b)
  • A 1 (2, 3, 4) 5 9 ()
  • B 1 [2, 3, 4] 5 ValueError
  • C 1 [2, 3, 4] 5 9 [] Correct
  • D 1 2 5 9 None
Correct Answer: Option C

The starred name always gets a list – possibly empty.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links