ProgrammingModerateTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
import heapq
print(heapq.heappop([]) if False else 'ok', heapq.nlargest(1, []))
  1. A. ok []
  2. B. ok None
  3. C. IndexError
  4. D. []

Correct answer: A. ok []

The first expression is never evaluated, so the program never calls heappop on an empty list. nlargest(1, []) returns an empty list rather than None or an error.

More Python Programming questions

Exams that ask this topic