ProgrammingModerateProduct-company MCQ pattern

What is printed?

What is printed?
g = (i * i for i in range(4))
print(sum(g), sum(g))
  1. A. 30 0
  2. B. 6 6
  3. C. 14 14
  4. D. 14 0

Correct answer: D. 14 0

A generator can be iterated only once. The first sum uses up 0 + 1 + 4 + 9 = 14. The second sum gets an empty iterator and returns 0.

More Python Programming questions

Exams that ask this topic