ProgrammingModerateTCS NQT · Wipro pattern

What is printed?

What is printed?
a = []
for i in range(20):
    a.append(i)
print(len(a), a[-1], a.pop(), len(a))
  1. A. 20 19 19 20
  2. B. 20 19 19 19
  3. C. 19 19 19 19
  4. D. 20 19 18 19

Correct answer: B. 20 19 19 19

Python evaluates print's arguments from left to right. The length is 20 and the last item is 19 before pop removes 19, so the final length is 19.

More Python Programming questions

Exams that ask this topic