LearnFrenzy
Sign in Take a free test

Tuples · Predict the Output · Question 9

Starred unpacking of a short tuple Answer, explanation & discussion

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

What is the output of the following Python program?

main.py
a, *b = (1,)
*c, d = (7, 8, 9)
print(a, b, c, d)
  • A 1 () (7, 8) 9
  • B 1 [] [7, 8] 9 Correct
  • C 1 None [7, 8] 9
  • D ValueError
Correct Answer: Option B

A starred target gets a list, empty if nothing is left. It may stand at the start, middle or end.

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