liveBook · Manning

Statement

As explained in Get Programming: Learn to code with Python

A complete line or instruction of Python code that the interpreter executes as part of a program.

A statement is a line of Python code in a program. Statements are the instructions the interpreter executes. A program with several lines has several statements. section 5.3

Statement or expression?

Consider `3 + 2`, `a = 5 + 6`, and `print(21)`. Each is a statement. `3 + 2` is also an expression: it evaluates to the value `5`. The assignment stores a value, while `print(21)` displays one; neither action is classified as an expression here. section 5.3

You can try a line in the IPython console to see what it does. Entering `3 + 2` lets you inspect its result; entering `print(3 + 2)` prints `5` for a user to see. section 3.2

In a linear program, statements run in the order you wrote them, with none skipped or repeated. Decisions let a program choose which lines to execute—for example, according to user input. section 13.0

How Get Programming: Learn to code with Python covers it

How deep it goes
Defines a statement as a line of code and contrasts it with an expression through short examples, without detailing interpreter internals.
Examples
Uses arithmetic, assignment, and printing lines for classification, plus console trials that contrast inspected results with printed output.
What it assumes
Builds on basic Python values and variables while defining statements and expressions without assuming experience with program decisions.
What you can do after
Practice/perform classification of lines as statements or expressions and recognize when program decisions change which statements run.
How it connects
Connects statements to expressions, variable assignment, printing, and decision-making in programs.

Also explained in

Compare how 3 books explain statement →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Get Programming: Learn to code with Python. The section links point to the parts of the book it draws on.