What is a generator in Python?
- A A function that returns a list
- B A function containing yield that produces values lazily, one at a time
- C A class that creates objects
- D A random number producer
Answer
A function containing yield that produces values lazily, one at a time
Generators hold one value in memory at a time rather than the whole sequence, which is why they are used for large files and streams.





