Understanding Python Statements and Expressions

When you start learning Python, you will see terms like statement and expression. These words sound technical, but the idea is simple.

A statement is code that tells Python to do something.

An expression is code that Python evaluates to a value.

You will often see both working together in the same line of code. Once you understand that, beginner code becomes much easier to read.

Quick rule

x = 10
print(x + 5)

# x = 10 is a statement
# x + 5 is an expression
# print(x + 5) is a statement that contains an expression

Use this simple rule: an expression produces a value, while a statement performs an action.

What this page helps you understand

  • A statement is a line of code that does something
  • An expression is code that produces a value
  • Many Python lines contain both a statement and an expression
  • You do not need advanced theory to use this idea in practice

What is a statement in Python?

A statement tells Python to perform an action.

Common examples of statements include:

  • variable assignment
  • if statements
  • for loops
  • import statements
  • function definitions with def

Statements often:

  • control the flow of a program
  • create or change variables
  • run blocks of code
  • perform actions

A statement does not need to return a value.

Examples of statements

x = 10
import math

if x > 5:
    print("x is greater than 5")

In this example:

  • x = 10 is an assignment statement
  • import math is an import statement
  • if x > 5: starts an if statement
  • print("x is greater than 5") is commonly treated as a statement in beginner code because it performs an action

If you are still learning Python basics, it helps to first understand Python syntax basics because statements are a big part of Python syntax.

What is an expression in Python?

An expression is code that Python can evaluate to a value.

That value might be:

  • a number
  • a string
  • True or False
  • a list
  • the result of a function call

Examples of expressions

5
"hello"
x + 1
len("Sam")
age > 18

Each of these produces a value:

  • 5 produces the value 5
  • "hello" produces a string
  • x + 1 produces a calculated result
  • len("Sam") produces 3
  • age > 18 produces either True or False

Expressions can be simple or built from smaller parts.

You will often see expressions on the right side of = in Python variables.

Statement vs expression: the simple difference

The easiest way to remember the difference is this:

  • Expression = produces a value
  • Statement = performs an action

Here is a simple example:

price = 20
tax = 5
total = price + tax

print(total)

What is happening here?

  • total = price + tax is an assignment statement
  • price + tax is an expression
  • print(total) performs an action, so beginners usually treat it as a statement
  • total inside print(total) is an expression because Python evaluates it to its current value

Common examples beginners see

These are patterns you will see often in real code.

Assignment

name = "Sam"
  • name = "Sam" is a statement
  • "Sam" is an expression

Printing a value

print(name)
  • print(name) is usually treated as a statement in beginner explanations
  • name is an expression

Condition in an if statement

if score > 50:
    print("Pass")
  • if score > 50: is an if statement
  • score > 50 is the condition expression

If you want to go deeper into conditions, see Python if statements explained.

Loop

for item in items:
    print(item)
  • for item in items: is a for statement
  • item and items are names used in the statement

How statements and expressions work together

Statements and expressions are not separate worlds. In real Python code, statements often contain expressions.

Assignment uses an expression

x = 2 + 3
print(x)
  • x = 2 + 3 is a statement
  • 2 + 3 is the expression
  • Python evaluates the expression first, then assigns the result to x

Output:

5

If statements use expressions as conditions

age = 20

if age >= 18:
    print("Adult")
  • if age >= 18: is a statement
  • age >= 18 is an expression that becomes True or False

Function calls can produce values

name = "hello"
length = len(name)
print(length)
  • length = len(name) is a statement
  • len(name) is an expression because it returns a value
  • name is also an expression when Python reads its value

If functions still feel unclear, Python functions explained is a good next step.

How to identify each one in code

When you are not sure, ask these questions.

Ask: does this code produce a value?

If yes, it is an expression.

Examples:

  • 10
  • "cat"
  • x
  • x + 1
  • len(text)
  • 4 > 2

Ask: does this code tell Python to do something?

If yes, it is a statement.

Examples:

  • x = 10
  • if x > 5:
  • for item in items:
  • while count < 3:
  • def greet():
  • import math

Look for common statement patterns

These often signal statements:

  • =
  • if
  • for
  • while
  • def
  • import

Look for common expression patterns

These often signal expressions:

  • numbers
  • strings
  • variable names
  • calculations
  • comparisons
  • function results

Why this matters for beginners

This idea helps more than many beginners expect.

It can help you:

  • read code more clearly
  • understand what each part of a line is doing
  • make better sense of error messages
  • learn variables, conditions, loops, and functions faster
  • write cleaner Python code

You do not need formal computer science theory here. You just need to recognize:

  • what part gives a value
  • what part performs an action

That is enough for most beginner Python code.

Common mistakes

Beginners often get confused in these situations.

Thinking every line of code is only one thing

Some lines contain both a statement and one or more expressions.

Example:

x = 10 + 5
  • whole line: statement
  • 10 + 5: expression

Confusing assignment with calculation

In this code:

total = price + tax
  • total = ... is the statement
  • price + tax is the calculation expression

Assuming print() is the same as the value it displays

x = 7
print(x)

print(x) shows the value on the screen, but it is not the same thing as the value itself.

  • x is an expression
  • print(x) performs an action

Not realizing conditions are expressions

x = 10
print(x > 5)

Here, x > 5 is an expression. It produces True or False.

Try these examples yourself

Run these small examples and notice which parts are statements and which parts are expressions.

print(type(5))
print(2 + 3)

x = 10
print(x)

print(len("hello"))
print(4 > 2)

Expected output:

<class 'int'>
5
10
5
True

What to notice:

  • 5, 2 + 3, x, len("hello"), and 4 > 2 are expressions
  • the print(...) lines perform actions
  • x = 10 is a statement that sets a variable

If you are new to variables, you may also want to read what a variable means in Python.

FAQ

Is print() a statement or an expression in Python?

In beginner-focused Python explanations, print(...) is best treated as a statement because it performs an action. The value inside print(...) is usually an expression.

Can a statement contain an expression?

Yes. This is very common.

Example:

x = 2 + 3

This is a statement that contains the expression 2 + 3.

Is a variable name an expression?

Yes. A variable name like x can be used as an expression because Python evaluates it to its current value.

Why do I need to learn statements and expressions?

It helps you understand how Python code is built. That makes it easier to read examples, write code, and fix mistakes.

See also

Understanding statements and expressions is a strong first step. The next best topics are Python syntax and variables, because these ideas become much clearer when you see them in real beginner code.