ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
print(list(map(int, '1 2 3'.split()))[::-1])
  1. A. [1, 2, 3]
  2. B. [3, 2]
  3. C. [3, 2, 1]
  4. D. ['3', '2', '0']

Correct answer: C. [3, 2, 1]

split gives the strings 1, 2 and 3, map converts them to ints, and the reversed slice gives 3, 2, 1.

More Python Programming questions

Exams that ask this topic