Computer Science · Ch 5 — Getting Started with Python
Statement
5.10
Statement
In Python, a statement is a unit of code that the Python interpreter can execute. Where an expression evaluates to a value, a statement is an instruction — something the interpreter carries out.
We have already been using statements throughout this chapter. Two familiar kinds are:
- Assignment statements — create a variable and store a value in it.
- Print statements — display output on the screen.
>>> x = 4 # assignment statement
>>> cube = x ** 3 # assignment statement (evaluates x ** 3, stores the result)
>>> print(x, cube) # print statement
4 64
The first line assigns 4 to x. The second evaluates the expression x ** 3 (that is, 4 raised to the power 3) and assigns the resulting value 64 to the variable cube. The third statement prints both values, producing the output 4 64. …