Skip to content
BENIBIX Learn

Expression

Development🧩 Programming ConceptsPrograms

A piece of code that works out to one value, like 3 + 4.

Think of it like

Think of it like a sum on a calculator. You type 3 + 4, and it gives back one answer.

Example

In price * 2, the computer looks up price, doubles it and gets 20. That 20 is the value of the expression.

Why it matters

Most of what a program computes happens inside expressions. Reading them well is reading what the code really does.

Definition

An expression is a piece of code that works out to a value. 3 + 4 is an expression, and its value is 7. A name of a variable is an expression too, and so is a question like age > 10. The computer works out the value, then uses it. Expressions often sit inside statements, the way a sum sits inside a sentence.

Example code

python
>>> 3 * 4 + 2
14
>>> 10 > 3
True
Each line works out to one value: a number, then True.

Common mistake

Thinking an expression changes things by itself. It only works out a value. A statement has to use it.

Key takeaways

  1. 1
    Gives a value. Every expression works out to one result.
  2. 2
    Can nest. Small expressions build bigger ones.
  3. 3
    Lives in statements. A statement uses the value it gives.

Compare

Learn it properly