all Python 3astterm
ast.Delete
statements
The node of a del statement: a list of targets, each of them with the Del context.
Syntax
ast.Delete(targets)
del a, b yields two separate targets, not a Tuple — unlike the assignment a, b = …; but del (a, b) with parentheses yields a single Tuple target. Targets can be Name, Attribute and Subscript — del d['k'] deletes an item, not a variable. The deletion context itself is the ast.Del class.
Examples
import ast
node = ast.parse("del d['k'], b").body[0]
print([type(t).__name__ for t in node.targets]) # → ['Subscript', 'Name']
grouped = ast.parse('del (a, b)').body[0]
print([type(t).__name__ for t in grouped.targets]) # → ['Tuple']
See also
Open in the full glossarydocs.python.orgReport an inaccuracy