Statements and ExpressionsΒΆ
- A statement is an instruction that the Python interpreter can execute.
- We have only seen the assignment statement so far.
- Some other kinds of statements that we’ll see shortly are
while
statements,for
statements,if
statements, andimport
statements.
- An expression is a combination of values, variables, operators, and calls to functions. Expressions need to be evaluated.
- If you ask Python to
print
an expression, the interpreter evaluates the expression and displays the result.
(ch02_13)
We’ve previously seen the print
and the type
functions, so len
is our third example of a function!
- The evaluation of an expression produces a value, which is why expressions can appear on the right hand side of assignment statements.
- A value all by itself is a simple expression, and so is a variable.
- Evaluating a variable gives the value that the variable refers to.
(ch02_14)