Skip to main content
Back to module
Math for Tech & STEM · Algebra Essentials

Variables and expressions

Reading34mLesson 1 of 3 in this module

Read, simplify and evaluate algebraic expressions using the order of operations.

Why this matters

A spreadsheet formula, a line of code and a physics equation all share one skill: writing a calculation with variables so it works for any input. Once you can read and evaluate expressions, formulas stop looking like secret codes and start looking like recipes.

The core idea

A variable is a letter (or a name) that stands for a number that can change. An expression combines numbers, variables and operations, such as 3x + 5 or 2πr. An expression does not have an equals sign; it describes a value. (An equation says two expressions are equal; that is the next lesson.)

Some vocabulary:

  • In 4x² − 7x + 2, the terms are 4x², −7x and 2.
  • 4 and −7 are coefficients; 2 is a constant.
  • 3x means 3 × x. Writing two things side by side means multiply.

In code, multiplication is never implied: you must write 3 * x, and powers use ** in Python.

Order of operations

Everyone must evaluate an expression the same way, so there is an agreed order:

  1. Parentheses (brackets) first
  2. Exponents (powers and roots)
  3. Multiplication and division, left to right
  4. Addition and subtraction, left to right

You may know this as PEMDAS or BODMAS. Note that multiplication does not beat division; they share a level and you work left to right. So 12 ÷ 3 × 2 = 4 × 2 = 8, not 12 ÷ 6 = 2.

Worked example 1: evaluating

Evaluate 3x² − 2xy + 5 when x = 2 and y = 1.

  1. Substitute, using parentheses to be safe: 3(2)² − 2(2)(1) + 5
  2. Exponent: 3(4) − 2(2)(1) + 5
  3. Multiply: 12 − 4 + 5
  4. Add and subtract left to right: 13

Substituting with parentheses matters most with negatives. If x = −3, then x² = (−3)² = 9. Writing −3² without parentheses means −(3²) = −9.

Worked example 2: combining like terms

Like terms have exactly the same variable part, so they can be added: 5x + 3x = 8x. Terms like 5x and 3x² are not alike and cannot be combined.

Simplify 4a + 3b − a + 2b − 6:

  • a-terms: 4a − a = 3a
  • b-terms: 3b + 2b = 5b
  • constant: −6
  • Result: 3a + 5b − 6

Worked example 3: the distributive property

Multiply everything inside the parentheses by what is outside:

3(2x − 4) = 6x − 12

−2(x + 5) = −2x − 10 (the negative sign is distributed too)

Simplify 2(x + 3) + 4(x − 1): 2x + 6 + 4x − 4 = 6x + 2.

You can check a simplification by plugging in a number. With x = 1: the original gives 2(4) + 4(0) = 8 and the simplified version gives 6 + 2 = 8. Matching values at a couple of points is strong evidence the algebra is right.

Expressions in code

x = 2
y = 1
value = 3 * x**2 - 2 * x * y + 5
print(value)   # 13

Python follows the same order of operations, with ** done before *. When in doubt, add parentheses; they cost nothing and make intent clear.

A real example

A cloud service costs $0.023 per GB stored plus $0.09 per GB downloaded. Monthly cost as an expression: 0.023s + 0.09d. For s = 500 and d = 120: 11.5 + 10.8 = $22.30. The expression is reusable every month; only the inputs change.

Common mistakes

  • Squaring a negative without parentheses. (−3)² = 9 but −3² = −9.
  • Combining unlike terms, such as turning 2x + 3x² into 5x³.
  • Distributing to only the first term: 3(x + 4) is 3x + 12, not 3x + 4.
  • Doing multiplication before division regardless of position. They are equal priority; go left to right.

Quick recap

  • Variables stand for numbers; expressions combine them without an equals sign.
  • Follow the order of operations; use parentheses when substituting.
  • Combine only like terms; distribute to every term in the parentheses.
  • Check a simplification by substituting a test value.

Try it

In the Do tab, translate 3x² − 2xy + 5 into Python so the function returns the right value for any x and y.

Also in this lesson: