"can generator be used more than once?" Code Answer
3
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:
three_line_gen()
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.
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
and iterate over
mygen
twice, the second time will fail as you expect.