Expressions ca be used as statements, on a line by itself. In this case the result of the expression won’t be saved, so, expressions are commonly used as statements in two situations:
- For calls to functions and methods – Some functions and methods do their work without returning a value so you may want to call these functions with expression statements.
- For printing values at the terminal – Python echoes back the results of expressions typed at the terminal line.
Common Python expression statements:
- Function calls –
- Method calls –
- Printing variables in the terminal –
- Printing operations –
print(a, b, c, sep='')
- Yielding expression statements –
yield x ** 2
Expressions can appear as statements in Python, statements cannot be used as expressions. A statement that is not an expression must generally appear on a line all by itself, not nested in a larger syntactic structure.