When you yield a generator, you aren’t just pausing execution to extract a value. You can also use that time to send a value to what is yielding.

This will return No Customer followed by 13 . This can get confusing, especially if you are just reading the code, and not running it. So try running it!

When you need to send data to your generator function, you can’t have the generator function be part of a loop. Instead assign it to a variable so you can manually handle next/send. (In the above example, I assign the generator to the action variable)

Once you have the action variable, you need to step over to the next yield. This is done with the next() function. Warning: executing send() before next() , you will get a TypeError: can't send non-None value to a just-started generator error.