(such as a string, tuple or list) or other iterable object:
.. productionlist:: python-grammar
- for_stmt: "for" `target_list` "in" `expression_list` ":" `suite`
+ for_stmt: "for" `target_list` "in" `starred_list` ":" `suite`
: ["else" ":" `suite`]
The expression list is evaluated once; it should yield an iterable object. An
-iterator is created for the result of the ``expression_list``. The suite is
-then executed once for each item provided by the iterator, in the order returned
-by the iterator. Each item in turn is assigned to the target list using the
-standard rules for assignments (see :ref:`assignment`), and then the suite is
-executed. When the items are exhausted (which is immediately when the sequence
-is empty or an iterator raises a :exc:`StopIteration` exception), the suite in
-the :keyword:`!else` clause, if present, is executed, and the loop terminates.
+iterator is created for the result of the ``starred_list``. The expression
+list can contain starred elements (``*x, *y``) that will be unpacked in the
+final iterator (as when constructing a ``tuple`` or ``list`` literal). The
+suite is then executed once for each item provided by the iterator, in the
+order returned by the iterator. Each item in turn is assigned to the target
+list using the standard rules for assignments (see :ref:`assignment`), and then
+the suite is executed. When the items are exhausted (which is immediately when
+the sequence is empty or an iterator raises a :exc:`StopIteration` exception),
+the suite in the :keyword:`!else` clause, if present, is executed, and the loop
+terminates.
.. index::
statement: break
emulate the effect of Pascal's ``for i := a to b do``; e.g., ``list(range(3))``
returns the list ``[0, 1, 2]``.
+.. versionchanged:: 3.11
+ Starred elements are now allowed in the expression list.
.. _try:
.. _except: