SythraOpen app

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.

Sythra

6 min read

XLinkedIn
Statements vs Expressions in Python — cover illustration

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
6

What you see:

  • 5 is an expression — the REPL prints its value
  • x = 5 is an assignment statement — no value displayed
  • x + 1 is an expression — the REPL prints 6

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 + 1

What happens? Nothing visible. Because:

  • 5 is an expression — evaluated, then discarded
  • x + 1 is an expression — evaluated, then discarded
  • Neither is printed

Now make the values speak:

print(5)
x = 5
print(x + 1)

# Output:
# 5
# 6

Script 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
# 2

Notice the middle line:

x = 2

Assignment 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 modeScript mode
Immediate feedbackRuns the entire file
Expressions auto-displayMust use print() (or similar)
Good for testingGood for building programs
Feels like a calculatorFeels 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.

Browse all python explainers →