"can generator be used more than once?" Code Answer


three_line_gen is not a generator, it's a function. what it returns when you call it is a generator, a brand new one each time you call it. each time you put parenthesis like this:


it is a brand new generator to be iterated on. if however you were to first do

mygen = three_line_gen()

and iterate over mygen twice, the second time will fail as you expect.

By luizMello on February 13 2022
Only authorized users can answer the Search term. Please sign in first, or register a free account.