ExamVeda
Login
Home
Generators and Iterators
?

What is a generator in Python?

Answer & Solution
Correct Answer: Option D
The correct answer is Option D: A function that yields values one at a time.
Generators in Python are functions defined using the yield statement. They generate values lazily, one at a time, allowing for efficient memory usage, especially with large datasets. When called, a generator function returns an iterator object but does not start execution immediately. Instead, it suspends its state and resumes execution when the next() method is called on the iterator object. This makes generators a powerful tool for handling large datasets or infinite sequences efficiently.
Examveda
Question posted by Examveda
Community

Join the Discussion

No comments yet Be the first to discuss this question.