Statements vs Expressions in Python
In Python, an expression produces a value; a statement performs an action. The REPL auto-displays expression results, but a script stays silent unless you print() — which is why the same lines can “work” interactively and do nothing in a file.
Want to understand statements vs expressions in Python? An expression produces a value. A statement performs an action. Mix those up — especially between the interactive prompt and a .py file — and beginners often think Python “stopped working.”
This page locks the difference, then shows the classic experiment: the same lines look loud in interactive mode and silent in a script until you add print(). Pair it with Operators and Operands (how expressions are built) and Variables (assignment as a statement).
What you will learn
By the end you can:
- Define expression vs statement in one sentence each
- Predict what interactive mode will display
- Explain why a script can “do nothing” with the same lines
- Know when to reach for
print() - See why assignment changes state without speaking
We are not covering expression statements in the formal grammar sense, walrus
:=, or every statement type (if,for, …). This page is the beginner distinction that clears the biggest REPL-vs-file confusion.
Expression vs statement — the one-line definitions
- An expression produces a value
- A statement performs an action
Examples of expressions: 5, x + 1, 10 / 2, "hi" + "!". Each evaluates to something.
Examples of statements: x = 5, print(x), import math. They tell Python to do something — bind a name, write output, load a module.
A small experiment — interactive mode
Try this at the Python prompt (interactive mode):
>>> 5
5
>>> x = 5
>>> x + 1
6What you see:
5is an expression — the REPL prints its valuex = 5is an assignment statement — no value displayedx + 1is an expression — the REPL prints6
Interactive mode feels like a calculator: evaluate, show, repeat.
The same lines in a script
Put those lines in a .py file and run it:
5
x = 5
x + 1What happens? Nothing visible. Because:
5is an expression — evaluated, then discardedx + 1is an expression — evaluated, then discarded- Neither is printed
Now make the values speak:
print(5)
x = 5
print(x + 1)
# Output:
# 5
# 6Script mode behaves as expected once output is explicit. The expressions did not change — only how you asked to see them.
Scripts execute line by line
A script is usually a sequence of statements. Python runs them top to bottom:
print(1)
x = 2
print(x)
# Output:
# 1
# 2Notice the middle line:
x = 2Assignment produces no output. It changes the state of the program — the name x now refers to 2 — but it does not speak unless you tell it to. Actions without display are still real work.
Python REPL vs script — why output disappears
| Interactive mode | Script mode |
|---|---|
| Immediate feedback | Runs the entire file |
| Expressions auto-display | Must use print() (or similar) |
| Good for testing | Good for building programs |
| Feels like a calculator | Feels like an execution engine |
Interactive mode is where you experiment. Script mode is where you build.
Common mistakes
- Expecting a bare expression in a script to print itself
- Thinking assignment “didn’t run” because nothing appeared on screen
- Confusing
=(statement / assign) with==(expression / compare) - Assuming the REPL and a file must look identical line-for-line
Why this distinction matters
Understanding statements vs expressions removes a huge layer of beginner confusion. You stop blaming Python for silence and start choosing: compute a value, perform an action, or both — and print when you need to see it.
Common questions
What is an expression in Python?
An expression is any piece of code that evaluates to a value — for example 5, x + 1, len("hi"), or 10 / 2. Expressions can be nested inside other expressions.
What is the difference between a statement and an expression in Python?
An expression produces a value. A statement performs an action. For example, x + 1 is an expression; x = 5 is a statement.
Why does my Python script print nothing when the REPL showed a value?
Interactive mode automatically displays the result of expressions. Script mode does not. Put print(...) around the expression if you want to see it.
Is assignment a statement or an expression in Python?
Assignment (x = 5) is a statement. It changes the program’s state by binding a name to a value, but it does not produce a value you can print by writing the assignment alone.
Does print() count as a statement?
print(...) is a statement that performs the action of writing output. The thing inside the parentheses is often an expression whose value gets printed.
What is interactive mode vs script mode in Python?
Interactive mode (the REPL) runs line by line and shows expression results immediately. Script mode runs a whole .py file; only explicit output like print() appears.
Explore
Related topics
Keep going — these sit next to this concept in a real learning path.
Operators and Operands in Python
Expressions are built from operators acting on operands.
Order of Operations in Python
PEMDAS, precedence, parentheses, and left-to-right ties.
Variables in Python
Assignment statements give names to values.
Programs, Interpreters & Compilers in Python
How Python runs what you type — REPL vs files.
Types, Values, and Errors in Python
The values that expressions produce.
Interactive Mode vs Script Mode in Python
Why the same line of code behaves differently in each mode.
Python course hub
All free Python explainers and the path into Agentic practice.