ProgrammingVery hardTCS Digital · Product companies

What does this Python code print? it = iter([1, 2, 3, 4, 5]) print(any(x > 2 for x in it), next(it))

  1. A. True 3
  2. B. True 5
  3. C. True 1
  4. D. True 4

Correct answer: D. True 4

any() stops as soon as it sees 3, having consumed 1, 2 and 3 from the shared iterator. The next call to next(it) therefore returns 4.

More Python Programming questions

Exams that ask this topic