Skip to Content
Secret Recipes of the Python Ninja
book

Secret Recipes of the Python Ninja

by Cody Jackson
May 2018
Intermediate to advanced content levelIntermediate to advanced
380 pages
9h 37m
English
Packt Publishing
Content preview from Secret Recipes of the Python Ninja

How it works...

Here is an example of a generator in action:

  • The line 1 simply creates the function as provided previously.
  • The line 2 calls the generator like a normal function, showing that generators can operate exactly like a regular function. You could capture the results in a list object if you wanted a permanent copy of the results.
  • The line 3 creates an instance of the generator.
  • The lines 4-6 show how a generator is typically used. By calling the generator instance as the argument for next(), the generator processing is paused after each evaluation cycle. Rather than receiving all results at once, only one value is provided from ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The Expanding World of Python

The Expanding World of Python

Dane Hillard

Publisher Resources

ISBN: 9781788294874Supplemental Content