class astroid.nodes.For(lineno: int | None, col_offset: int | None, parent: NodeNG | None, *, end_lineno: int | None, end_col_offset: int | None)[source]#

Bases: MultiLineWithElseBlockNode, AssignTypeNode, Statement

Class representing an ast.For node.

>>> import astroid
>>> node = astroid.extract_node('for thing in things: print(thing)')
>>> node
<For l.1 at 0x7f23b2e8cf28>
assigned_stmts(**kwargs: _P.kwargs) Generator[InferenceResult, None, None]#

Returns the assigned statement (non inferred) according to the assignment type. See astroid/ for actual implementation.

property blockstart_tolineno#

The line on which the beginning of this block ends.



body: list[NodeNG]#

The contents of the body of the loop.


Get the child nodes below this node.

iter: NodeNG#

What the loop iterates over.

optional_assign: ClassVar[bool] = True#

Whether this node optionally assigns a variable.

This is always True for For nodes.

orelse: list[NodeNG]#

The contents of the else block of the loop.

postinit(target: NodeNG, iter: NodeNG, body: list[NodeNG], orelse: list[NodeNG], type_annotation: NodeNG | None) None[source]#
target: NodeNG#

What the loop assigns to.

type_annotation: NodeNG | None#

If present, this will contain the type annotation passed by a type comment