To understand it through Python yield characteristics

You must first know what is the Builder

Generator is iterable, but with a different list, you can only read it once. Generator not return a value, so use the yield.

Use generator may save memory.

Keyword yield

yield characteristics:

  • yield analogous to return, but the yield is to generate a return object
  • The first iteration of a generator function, from the beginning to the yield, the yield value and then returns as a return value of the first iteration, the next time this function is executed, and a subsequent iteration, rather than starting from scratch.
  • When the loop end of the last yield, the generator will be considered vacant.

Guess you like

Origin www.cnblogs.com/goooood/p/12547667.html