generators are like function but it not returning value. but it generates using yield keyword example : def simpleGenerator(): yield 1 yield 2 yield 3 for value in simpleGenerator(): print(value) then output : 1 2 3
generator is like a normal function, but they do not return a value, they yield it. If the body of a def contains yield, the function automatically becomes a generator function.