Python Programming - Generators - Discussion

Discussion Forum : Generators - General Questions (Q.No. 18)
18.
What is the primary advantage of using the yield statement in a generator over returning a list?
Generators allow for random access of elements
Generators consume less memory compared to lists
Generators are faster in execution
Generators automatically handle exceptions
Answer: Option
Explanation:
Generators are memory-efficient as they produce values on-the-fly and do not store the entire sequence in memory. This makes them suitable for handling large datasets or infinite sequences without using excessive memory.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.