Generators

  • Generator functions allow us to describe sequences using imperative code.

  • Generator functions contain at least one use of the yield keyword.

  • Generators are iterators. When the iterator is advanced with next() the generator starts or resumes execution up to and including the next yield.

  • Each call to a generator function creates a new generator object.

  • Generators can maintain explicit state in local variables between iterations.

  • Generators are lazy and so can model infinite series of data.

  • Generator expressions have a similar syntactic form to list comprehensions and allow for a more declarative and concise way of creating generator objects.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset