---
title: Statements vs Expressions in Python
source: https://app.sythra.ai/learn/python/statements-vs-expressions
topic: Python
updated: 2026-08-12
publisher: Sythra (https://app.sythra.ai)
---

# 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.

_Source: [https://app.sythra.ai/learn/python/statements-vs-expressions](https://app.sythra.ai/learn/python/statements-vs-expressions) — free to read on Sythra._

## Key points

- An expression produces a value (5, x + 1, 10 / 2)
- A statement performs an action (assignment, print, import)
- Interactive mode shows expression results automatically
- Script mode only shows output when you print()
- Assignment changes state but prints nothing on its own
- If it worked in the REPL but not in a file, ask: did I forget print()?

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](/learn/python/operators-operands) (how expressions are built) and [Variables](/learn/python/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.

> **Mode matters:** 

## A small experiment — interactive mode

Try this at the Python prompt (interactive mode):

```python
>>> 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:

```python
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:

```python
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:

```python
print(1)
x = 2
print(x)

# Output:
# 1
# 2
```

Notice the middle line:

```python
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 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**.

> **Debugging mantra:** 

## 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.

> **Practice with Sythra:**  [Practice with AI tutor](https://app.sythra.ai/pricing)

## FAQ

### 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.

## Related

- [Operators and Operands in Python](https://app.sythra.ai/learn/python/operators-operands) — Expressions are built from operators acting on operands.
- [Order of Operations in Python](https://app.sythra.ai/learn/python/order-of-operations) — PEMDAS, precedence, parentheses, and left-to-right ties.
- [Variables in Python](https://app.sythra.ai/learn/python/variables) — Assignment statements give names to values.
- [Programs, Interpreters & Compilers in Python](https://app.sythra.ai/learn/python/programs-interpreters-compilers) — How Python runs what you type — REPL vs files.
- [Types, Values, and Errors in Python](https://app.sythra.ai/learn/python/types-values-errors) — The values that expressions produce.
- [Interactive Mode vs Script Mode in Python](https://app.sythra.ai/learn/python/interactive-mode-vs-script-mode) — Why the same line of code behaves differently in each mode.
- [Python course hub](https://app.sythra.ai/learn/python) — All free Python explainers and the path into Agentic practice.

---

Written by Sythra — Learn machine learning by building. Practice this topic with Sythra's AI tutor: https://app.sythra.ai/pricing
