Python Programming - Generators - Discussion

Discussion Forum : Generators - General Questions (Q.No. 54)
54.
How does the generator.__iter__() method differ from the iter(generator) built-in function when applied to a generator?
They are equivalent in functionality
generator.__iter__() returns a new iterator, while iter(generator) returns the generator itself
iter(generator) returns a new iterator, while generator.__iter__() returns the generator itself
generator.__iter__() is used for generators, and iter(generator) is used for other iterable objects
Answer: Option
Explanation:
generator.__iter__() returns a new iterator object for the generator, while iter(generator) returns the generator itself.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.