What happens when a Python function contains the yield keyword?
A
It returns a generator that yields lazily
Correct answer
B
It returns all of its values at once in a list
C
It can only be called once in the whole program
D
It pauses the entire program until input arrives
Correct answer
A. It returns a generator that yields lazily
20 views
⚔️
Challenge a friend on Python
Same MCQs, timed, live leaderboard. Send the link on WhatsApp – no sign-up needed.
Create challenge
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
Doubts & discussionNot sure why the answer is A? Ask here and get an explanation.
Ask a doubt about this MCQ
‹ Previous MCQ In Python, a decorator is: Next MCQ › In standard CPython, what is the main effect of the Global Interpreter Lock (GIL)?