2.6. Statements and Expressions

A statement is an instruction that the Python interpreter can execute. We have seen the declaration and assignment statements so far. Some other kinds of statements that we’ll see shortly are while statements, for statements, and if statements. (There are other kinds too!)

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.

In this example len is a built-in Python function that returns the number of characters in a string. We’ve previously seen the print, str, float, and int functions, so this is our fifth 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.

You have attempted of activities on this page
Next Section - 2.7. Operators and Operands