ProgrammingHardProduct Company SDE · Python internals

What does the following Python 3 code print? a, *b, c = [1, 2, 3, 4, 5] print(a, b, c)

  1. A. 1 2 5
  2. B. 1 [2, 3, 4] 5
  3. C. 1 [2, 3] 4
  4. D. [1] [2, 3, 4] [5]

Correct answer: B. 1 [2, 3, 4] 5

Starred assignment makes b grab every element not claimed by a (first) and c (last): a=1, b=[2,3,4], c=5.

More Python Programming questions

Exams that ask this topic