ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
x = [1, 2, 3]
it = iter(x)
print(next(it), sum(it), list(it))
  1. A. 1 5 []
  2. B. 1 5 [2, 3]
  3. C. 1 6 []
  4. D. 1 [2, 3] []

Correct answer: A. 1 5 []

next takes 1 from the iterator. sum consumes the rest, 2 and 3, giving 5, so the iterator is empty by the time list(it) runs.

More Python Programming questions

Exams that ask this topic