[Corso Python3] visti sabato scorso...

alessandro medici alexxandro.medici a gmail.com
Mer 15 Giu 2016 23:53:22 CEST


generator

A function which returns a generator iterator
<https://docs.python.org/3.6/glossary.html#term-generator-iterator>. It
looks like a normal function except that it contains yield
<https://docs.python.org/3.6/reference/simple_stmts.html#yield> expressions
for producing a series of values usable in a for-loop or that can be
retrieved one at a time with the next()
<https://docs.python.org/3.6/library/functions.html#next> function.

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.
generator iterator

An object created by a generator
<https://docs.python.org/3.6/glossary.html#term-generator> function.

Each yield <https://docs.python.org/3.6/reference/simple_stmts.html#yield>
temporarily
suspends processing, remembering the location 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 expression

An expression that returns an iterator. It looks like a normal expression
followed by a for
<https://docs.python.org/3.6/reference/compound_stmts.html#for> expression
defining a loop variable, range, and an optional if
<https://docs.python.org/3.6/reference/compound_stmts.html#if> expression.
The combined expression generates values for an enclosing function:
>>>

>>> sum(i*i for i in range(10))         # sum of squares 0, 1, 4, ... 81285
-------------- parte successiva --------------
Un allegato HTML è stato rimosso...
URL: <http://lists.fsugpadova.org/pipermail/fsug-corso-python3/attachments/20160615/d9d63d24/attachment.html>


Maggiori informazioni sulla lista fsug-corso-python3