Skip to content

Commit 6873af5

Browse files
committed
doc: clarify for_stmt grammar by replacing starred_list with expression_list
1 parent e123a1d commit 6873af5

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Doc/reference/compound_stmts.rst

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,21 +151,22 @@ The :keyword:`!for` statement
151151
single: : (colon); compound statement
152152

153153
The :keyword:`for` statement is used to iterate over the elements of a sequence
154-
(such as a string, tuple or list) or other iterable object:
154+
(such as a string, tuple, or list) or other iterable object:
155155

156156
.. productionlist:: python-grammar
157-
for_stmt: "for" `target_list` "in" `starred_list` ":" `suite`
157+
for_stmt: "for" `target_list` "in" `expression_list` ":" `suite`
158158
: ["else" ":" `suite`]
159159

160-
The ``starred_list`` expression is evaluated once; it should yield an
161-
:term:`iterable` object. An :term:`iterator` is created for that iterable.
162-
The first item provided
163-
by the iterator is then assigned to the target list using the standard
164-
rules for assignments (see :ref:`assignment`), and the suite is executed. This
165-
repeats for each item provided by the iterator. When the iterator is exhausted,
166-
the suite in the :keyword:`!else` clause,
160+
The ``expression_list`` is evaluated once; it should yield an :term:`iterable` object.
161+
An :term:`iterator` is created for that iterable. The first item provided by the iterator
162+
is then assigned to the target list using the standard rules for assignments
163+
(see :ref:`assignment`), and the suite is executed. This repeats for each item provided
164+
by the iterator. When the iterator is exhausted, the suite in the :keyword:`!else` clause,
167165
if present, is executed, and the loop terminates.
168166

167+
Note that as of Python 3.11, unpacking with starred expressions (e.g., ``*x``) is supported
168+
in the iterable expression list.
169+
169170
.. index::
170171
pair: statement; break
171172
pair: statement; continue

0 commit comments

Comments
 (0)