About 50 results
Open links in new tab
  1. Understanding generators in Python - Stack Overflow

    Note: this post assumes Python 3.x syntax.† A generator is simply a function which returns an object on which you can call next, such that for every call it returns some value, until it raises a StopIteration …

  2. python - What can you use generator functions for? - Stack Overflow

    The generator approach is that the work-function (now a generator) knows nothing about the callback, and merely yields whenever it wants to report something. The caller, instead of writing a separate …

  3. What does the "yield" keyword do in Python? - Stack Overflow

    Oct 24, 2008 · Yield in Python used to create a generator function. Generator function behaves like an iterator, which can be used in loop to retrieve items one at a time. When a generator function is …

  4. How can I type hint a generator in Python 3? [duplicate]

    A Generator object is produced by calling a generator function, which is defined using the yield keyword. The Generator type is unique as it has two additional type parameters for its send and return types, …

  5. What is the return type hint of a generator function?

    Apr 27, 2017 · 102 As of Python 3.9, you can annotate a generator using the Generator[YieldType, SendType, ReturnType] generic type from collections.abc. For example:

  6. What does the yield keyword do in Python, and when should I use a ...

    Nov 26, 2025 · Is there a specific part of the documentation that you found unclear? Including your own example code showing a simple generator or a simple function returning a list would go a long way to …

  7. Python: passing argument to generator object created by generator ...

    18 Since a generator expression cannot have its own scope, the preferred approach would be to define a generator function as you suggested.

  8. python - How to loop through a generator - Stack Overflow

    I would like to measure the execution time of each generator invocation. What's a reasonably elegant & pythonic way to structure a loop that can get the timestamp before and after each invocation?

  9. What is the purpose of the "send" function on Python generators?

    generator.send(value) Resumes the execution and “sends” a value into the generator function. The value argument becomes the result of the current yield expression. The send() method returns the …

  10. python - Difference between function and generator? - Stack Overflow

    Apr 25, 2015 · A generator is very similar to a function that returns an array, in that a generator has parameters, can be called, and generates a sequence of values. However, instead of building an …