ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
def f():
    yield 1
    yield 2
print(sum(f()), max(f()), list(zip(f(), f())))
  1. A. 3 2 [(1, 1), (2, 2)]
  2. B. 3 2 [(1, 1)]
  3. C. 3 2 [(1, 2)]
  4. D. 6 2 [(1, 1), (2, 2)]

Correct answer: A. 3 2 [(1, 1), (2, 2)]

Each call to f() makes a new generator, so every use starts from 1. zip pairs the two fresh generators item by item.

More Python Programming questions

Exams that ask this topic