ast.Assign.targets
is a list
a, b = c, d
Yields following AST:
Assign(
targets=[
Tuple(
elts=[
Name(id='a', ctx=Store()),
Name(id='b', ctx=Store())],
ctx=Store())],
value=Tuple(
elts=[
Name(id='c', ctx=Load()),
Name(id='d', ctx=Load())],
ctx=Load()))
Under what conditions target
would be a list with multiple elements instead of
single Tuple
?
ast.Assign.targets
is a list
a, b = c, d
Yields following AST:
Assign(
targets=[
Tuple(
elts=[
Name(id='a', ctx=Store()),
Name(id='b', ctx=Store())],
ctx=Store())],
value=Tuple(
elts=[
Name(id='c', ctx=Load()),
Name(id='d', ctx=Load())],
ctx=Load()))
Under what conditions target
would be a list with multiple elements instead of
single Tuple
?
1 Answer
Reset to default 3When there are multiple destinations for the assignment of the value
. That is:
a = b = c = d
AST:
Module(
body=[
Assign(
targets=[
Name(id='a', ctx=Store()),
Name(id='b', ctx=Store()),
Name(id='c', ctx=Store())],
value=Name(id='d', ctx=Load()))],
type_ignores=[])
# ASSIGNMENT TARGETS
section of the grammar spec – juanpa.arrivillaga Commented Feb 10 at 19:14