1. Home
  2. Data Science
  3. Python
  4. What happens when a Python function contains the yield…

Added 2 Nov 2026

What happens when a Python function contains the yield keyword?

  1. It returns a generator that yields lazily Correct answer
  2. It returns all of its values at once in a list
  3. It can only be called once in the whole program
  4. It pauses the entire program until input arrives

Correct answer

A. It returns a generator that yields lazily

20 views

MCQSEXAM

Explanation

Generators compute values one at a time, keeping their state between yields, so a huge sequence such as lines of a 10 GB file never has to sit in memory.

Reference

Asked in: NTS, Python Developer Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Python MCQs

Practise all Python MCQs

Similar MCQs