ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
def f():
    yield 1
g = f()
print(type(f).__name__, type(g).__name__, hasattr(g, "__next__"), iter(g) is g, callable(g))
  1. A. function generator True True False
  2. B. generator generator True True False
  3. C. function generator True False True
  4. D. function iterator True True False

Correct answer: A. function generator True True False

Calling a generator function returns a generator object, an iterator whose __iter__ returns itself. It is not callable.

More Python Programming questions

Exams that ask this topic