-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
Closed
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dir
Description
Documentation
In ast module doc, it says:
class ast.For(target, iter, body, orelse, type_comment)
A for loop. target holds the variable(s) the loop assigns to, as a single Name, Tuple or List node.
Correction
The target can also be a Subscript or Attribute node.
Example:
for x.a in range(4):
print(x.a)
This parses to:
Module(
body=[
For(
target=Attribute(
value=Name(id='x', ctx=Load()),
attr='a',
ctx=Store()),
iter=Call(
func=Name(id='range', ctx=Load()),
args=[
Constant(value=4)],
keywords=[]),
body=[
Expr(
value=Call(
func=Name(id='print', ctx=Load()),
args=[
Attribute(
value=Name(id='x', ctx=Load()),
attr='a',
ctx=Load())],
keywords=[]))],
orelse=[])],
type_ignores=[])
Metadata
Metadata
Assignees
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dir