all Python 3astterm
ast.Expr
expressions
An expression statement: an expression standing on its own line whose value is discarded — a print(...) call, a docstring, a lone await.
Syntax
ast.Expr(value)
Almost every function call in a program body is an Expr wrapping a Call: when searching for calls, look into node.value. A docstring is an Expr too, the first one in the body, holding a string Constant. Do not confuse it with ast.Expression: that is the root of an 'eval'-mode tree, while Expr is an item of a module or function body list.
Examples
import ast
stmt = ast.parse('print(1)').body[0]
print(type(stmt).__name__, type(stmt.value).__name__) # → Expr Call
doc = ast.parse('def f():\n "Help text"').body[0].body[0]
print(type(doc).__name__, doc.value.value) # → Expr Help text
See also
Open in the full glossarydocs.python.orgReport an inaccuracy