← Quiz: Iterators and Generators: all 10 questions
Quiz: Iterators and Generators · Question 10 of 10
What is a key difference between return and yield?
What is a key difference between return and yield?
- A.yield pauses the function so it can continue later; return ends it
- B.return can send only numbers
- C.yield can only be used inside a class
- D.There is no difference
Answer & explanation
Correct answer: yield pauses the function so it can continue later; return ends it
After yield, local variables are kept and the function resumes from the same place.
Can you get the rest right without peeking?
Take the timed Quiz: Iterators and Generators quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →