Question
When should a Python developer choose Iterators, Generators, and yield deliberately?
- Choose Iterators, Generators, and yield mainly when you want to postpone validation and fix issues manually later.
- Choose Iterators, Generators, and yield whenever you want the code to look more advanced, even if the design gets less clear.
- Choose Iterators, Generators, and yield only to avoid modeling the real data shape or domain contract explicitly.
- Use generators when a consumer can stream results and holding the entire result set in memory would be unnecessary.
Hint
Think about the production scenario where the choice genuinely improves the code.
Answer and rationale
Correct answer: D. Use generators when a consumer can stream results and holding the entire result set in memory would be unnecessary.
Use generators when a consumer can stream results and holding the entire result set in memory would be unnecessary. Interviewers often ask this to see whether you can connect the concept to real design decisions.
Track: Python