ProgrammingHardCapgemini · Python

What is printed?

What is printed?
a, *b, c = range(5)
x, (y, *z) = 1, 'hey'
print(a, b, c, x, y, z)
  1. A. 0 [1, 2, 3] 4 1 h 'ey'
  2. B. 0 (1, 2, 3) 4 1 h ['e', 'y']
  3. C. 0 [1, 2, 3] 4 1 h ('e', 'y')
  4. D. 0 [1, 2, 3] 4 1 h ['e', 'y']

Correct answer: D. 0 [1, 2, 3] 4 1 h ['e', 'y']

A starred target always collects a list, even when the source is a string or tuple.

More Python Programming questions

Exams that ask this topic