ProgrammingVery hardGATE CS · Product-company placement

What is printed?

What is printed?
first, *mid, last = "abcde"
(a, b), *rest = [(1, 2), 3, 4]
*init, = range(3)
print(mid, last, a + b, rest, init)
  1. A. bcd e 3 (3, 4) (0, 1, 2)
  2. B. ['b', 'c', 'd'] e 3 [3, 4] SyntaxError
  3. C. ['b', 'c', 'd'] e (1, 2) [3, 4] range(0, 3)
  4. D. ['b', 'c', 'd'] e 3 [3, 4] [0, 1, 2]

Correct answer: D. ['b', 'c', 'd'] e 3 [3, 4] [0, 1, 2]

A starred target in assignment always collects into a list, even from a string or range. Nested targets unpack (1, 2) into a and b.

More Python Programming questions

Exams that ask this topic