What are Generators?

preview_player
Показать описание
Generator functions are a new way of programming. They allow us to control the execution of a function and even change the state of the function in mid execution.

I'll compare the generator function with a simple analogy; the traffic system. When you drive your car on the road your controlled by the traffic system. Whilst driving you'll eventually come to a stop sign or red light, you yield to allow other traffic to flow. But how does this apply to a generator function? Well in the same way you can stop or tell the generator function to yield; allowing for some other process to take place and come back later to execute more commands in the generator function.
Рекомендации по теме
Комментарии
Автор

Brilliant explanation! Hands down one of the best on this topic!

Abreviatur