diff options
Diffstat (limited to 'Doc/reference')
-rw-r--r-- | Doc/reference/expressions.rst | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst index e8efa9f..ac3c90f 100644 --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -232,6 +232,20 @@ and added to the set object. When a comprehension is supplied, the set is constructed from the elements resulting from the comprehension. +Variables used in the generator expression are evaluated lazily in a separate +scope when the :meth:`next` method is called for the generator object (in the +same fashion as for normal generators). However, the :keyword:`in` expression +of the leftmost :keyword:`for` clause is immediately evaluated in the current +scope so that an error produced by it can be seen before any other possible +error in the code that handles the generator expression. Subsequent +:keyword:`for` and :keyword:`if` clauses cannot be evaluated immediately since +they may depend on the previous :keyword:`for` loop. For example: +``(x*y for x in range(10) for y in bar(x))``. + +The parentheses can be omitted on calls with only one argument. See section +:ref:`calls` for the detail. + + .. _dict: Dictionary displays |