ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
print(next(iter([]), 'none'), next(iter([7])))
  1. A. nothing 7
  2. B. none 7
  3. C. none None
  4. D. StopIteration 7

Correct answer: B. none 7

next accepts a default that is returned when the iterator is exhausted, so no exception is raised for the empty list. The second call returns the only item, 7.

More Python Programming questions

Exams that ask this topic