ProgrammingModerateTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
a = [1, 2, 3]
r = a.reverse()
print(r, a)
  1. A. None [3, 2, 1]
  2. B. [3, 2, 1] [3, 2, 1]
  3. C. None [1, 2, 3]
  4. D. [3, 2, 1] [1, 2, 3]

Correct answer: A. None [3, 2, 1]

reverse() reverses the list in place and returns None, so r is None and a is changed.

More Python Programming questions

Exams that ask this topic