Generators Questions and Answers
Python Programming - Generators Questions with Answers focus on efficient data iteration using the `yield` keyword. These Python Generators Questions are helpful for TCS, Infosys, and Capgemini exams to test knowledge of memory-efficient programming techniques
Generators
Showing 10 of
25 questions
21. Can you reset a generator to its initial state?
- No
- Yes, using reset()
- Yes, using rewind()
- Yes, using restart()
22. What is a common use case for generators?
- Processing large files
- Mathematical calculations only
- GUI programming
- Database connections
23. What happens if you try to use a generator after it's exhausted?
- Raises StopIteration
- Starts from beginning
- Returns None
- Raises RuntimeError
24. Can generator functions have return statements?
- Yes, but it stops the generator
- No, syntax error
- Only in Python 3.3+
- Only without parameters
25. What is the performance benefit of generators?
- Memory efficiency and pipelining
- Faster CPU execution
- Better multithreading
- Automatic parallelization