Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions Doc/glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -641,23 +641,35 @@ Glossary
.. index:: single: generator

generator
A function which returns a :term:`generator iterator`. It looks like a
normal function except that it contains :keyword:`yield` expressions
for producing a series of values usable in a for-loop or that can be
retrieved one at a time with the :func:`next` function.
An :term:`iterator` object created by a :term:`generator function` or
a :term:`generator expression`.

Usually refers to a generator iterator object, but in some contexts
may refer to a :term:`generator function`. In cases where the
intended meaning isn't clear, using the full terms avoids ambiguity.

Usually refers to a generator function, but may refer to a
*generator iterator* in some contexts. In cases where the intended
meaning isn't clear, using the full terms avoids ambiguity.
.. index:: single: generator function

generator function
A function which returns a :term:`generator` object. It looks like a
normal function except that it contains :keyword:`yield` expressions
for producing a series of values usable in a :keyword:`for`\-loop or
that can be retrieved one at a time with the :func:`next` function.
See :pep:`255`.

generator iterator
An object created by a :term:`generator` function.
An object created by a :term:`generator function` or a
:term:`generator expression`.

Each :keyword:`yield` temporarily suspends processing, remembering the
execution state (including local variables and pending
try-statements). When the *generator iterator* resumes, it picks up where
it left off (in contrast to functions which start fresh on every
invocation).
execution state (including local variables and pending try-statements).
When the *generator iterator* resumes, it picks up where it left off
(in contrast to functions which start fresh on every invocation).

Generator iterators also implement the :meth:`~generator.send` method
to send a value into the suspended generator, and the
:meth:`~generator.throw` method to raise an exception at the point
where the generator was paused. See :pep:`342`.

.. index:: single: generator expression

Expand Down
Loading