Python's generators

Опубликовано: 15 Сентябрь 2017
на канале: Edik Mkoyan
111
1

http://www.dabeaz.com/finalgenerator/
A Python generator is a function which returns a generator iterator (just an object we can iterate over) by calling yield. yield may be called with a value, in which case that value is treated as the "generated" value. The next time next() is called on the generator iterator (i.e. in the next step in a for loop, for example),Rthe generator resumes execution from where it called yield, not from the beginning of the function. All of the state, like the values of local variables, is recovered and the generator contiues to execute until the next call to yield.

If this doesn't make any sense to you, don't worry. I wanted to get the textbook definition out of the way so I can explain to you what all that nonsense actually means.

Note: In recent years, generators have grown more powerful as features have been added through PEPs. In my next post, I'll explore the true power of yield with respect to coroutines, cooperative multitasking and asynchronous I/O (especially their use in the "tulip" prototype implementation GvR has been working on). Before we get there, however, we need a solid understanding of how the yield keyword and generators work.


На этой странице сайта вы можете посмотреть видео онлайн Python's generators длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Edik Mkoyan 15 Сентябрь 2017, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 111 раз и оно понравилось 1 зрителям. Приятного просмотра!