Concepts / What Is a Statement?

What Is a Statement?

A script executes statements sequentially, from top to bottom, with each statement completing before the next begins.

  • Programming

A Program Moves One Step at a Time

A Python program is a sequence of instructions. Python does not execute all of those instructions at once. It runs statements in order from top to bottom, and each statement completes before the next one begins. This ordering gives you a practical way to understand a program: start at the first statement, determine what it does, then continue to the next.

after completionafter completionStatement 1first unit of workStatement 2next unit of workStatement 3later unit of work
What happens next as the Python interpreter executes each statement from top to bottom?

A statement is a unit of code that the Python interpreter can execute. It is code that causes the interpreter to perform an action.

Tracing a Script

To predict what a multi-statement script will do, trace it line by line. For each statement, ask two questions: What does this statement do, and does it produce output? Also note whether it changes a variable, because a value assigned earlier remains available for use in later statements.

message = "Ready" print(message) print("Go")

nextnextdisplaysdisplaysmessage = Readystores a valueprint(message)outputs Readyprint(Go)outputs GoReadyfirst visible resultGosecond visible result
Which statements produce visible output, and in what order does that output appear?

Predicting the output order

What appears when Python executes the three statements from top to bottom?

Trace the assignment: The first statement stores Ready in message. It changes what value is available later, but it does not display anything.

Trace the first display: The second statement uses message with print(), so the stored value Ready is displayed.

Trace the second display: The third statement uses print() with Go, so Go is displayed after Ready.

The visible output is Ready on the first line, followed by Go on the second line.

Storing Versus Displaying

The two fundamental statement types highlighted here are expression statements, such as print(), and assignment statements, written in the form variable = value. They perform different kinds of work. An assignment statement stores a value in memory. A print() statement displays a result. Because storing and displaying are different actions, an assignment can change what later statements use without producing anything visible immediately.

storesshowsscore = 5stores 5print(score)displays a resultscorevalue available later5visible output
What changes when a value is assigned, and why might nothing appear on screen?
python
Output
5

Interactive Mode Responses

Interactive mode also follows the statement type. The interpreter executes each statement you enter in order and displays a result if there is one. Expression statements produce output in interactive mode, while assignment statements execute silently. This explains why entering a display-oriented statement can show something immediately, while entering an assignment may show no visible response even though the value is now available for later use.

displaysstores silentlyprint(Ready)expression statementmessage = Readyassignment statementReadyvisible resultmessagevalue available later
How does the interpreter respond differently when you enter an expression compared with an assignment?
Statement typeTypical formInteractive response
Expression statementprint(value)Produces output
Assignment statementvariable = valueExecutes silently and stores a value

The source distinguishes these two statement types by the action they perform and what appears in interactive mode.

Mistakes Beginners Make

  • Assuming every executed statement prints something

    An assignment stores a value but produces no output.

    Fix: Use print(total) when you want the stored value to appear.

  • Reading a multi-statement script as if all lines happen at once

    Python executes statements sequentially, from top to bottom, with each statement completing before the next begins.

    Fix: Trace the script one statement at a time and record output in execution order.

  • Thinking a silent assignment cannot affect later code

    Values assigned in earlier statements remain available for later statements.

    Fix: Track both visible output and changes to values as you trace.

Practice the Trace

What do you think happens?

What is displayed, and in what order, when this script runs? first = "One" second = "Two" print(second) print(first)

  • One, then Two
  • Two, then One
  • Nothing is displayed
  • The assignments are displayed before the print statements
Reveal answer

Answer: Two, then One

Python executes from top to bottom. The first two statements store values silently. The third statement displays the value stored in second, and the fourth displays the value stored in first.

EASY

Trace this script yourself. Identify which statements store values, identify which statements display results, and write the visible output in order. language = "Python" print("Learning") print(language)

Hints
  • Start with the assignment and decide whether it displays anything.
  • Then follow the two print() statements in their written order.
  • Use the stored value of language when tracing the final statement.

Why Statements Matter

Statements are the building blocks of programs because each one is an executable unit of work. A program may contain only a few statements or many thousands, but the interpreter applies the same basic model: read a statement, execute it, complete it, and move to the next. Once you can identify the statement type and trace the order, you can predict both what the program stores and what it displays.

  1. A statement is a unit of code that the Python interpreter can execute.
  2. Python executes statements sequentially from top to bottom, with each statement completing before the next begins.
  3. Assignment statements store values and produce no output.
  4. Expression statements such as print() display results in interactive mode.
  5. To predict a script, trace each statement and record both visible output and changes to values.

Key Takeaways

  • A statement is executable code that causes the Python interpreter to perform an action.
  • Statements run one after another from top to bottom.
  • Assignments store values silently, while print() statements display results.
  • Earlier assignments remain available to later statements.
  • Tracing each statement in order helps you predict output and debug programs.