It is fairly simple to create a generator in Python. It is as easy as defining a normal function with
yield statement instead of a
If a function contains at least one
yield statement (it may contain other
returnstatements), it becomes a generator function. Both
return will return some value from a function.
The difference is that, while a
returnstatement terminates a function entirely,
yieldstatement pauses the function saving all its states and later continues from there on successive calls.