A main building block of programs
2 + 3 = ?
🚫 Not what we’re doing 🚫
x + 3 = 5
, find x
🚫 Not what we’re doing 🚫
x + 3 = ?
Let the computer do the work.
👍 What we’re here for 👍
The simplest expression is a single value.
10
Operators allow us to combine expressions to get new expressions.
2 + 3
2
is a value (and thus an expression)
3
is a value (and thus an expression)
+
is an operator.
2 + 3
is an expression.
It evaluates to 5
.
+
- addition
-
- subtraction
*
- multiplication
/
- division
%
- remainder
**
- exponentiation
(2 + 3) / 10 ** 6
(2 + 3) / 10 ** 6
5 / 10 ** 6
5 / 1000000
0.000005
We assign values to names:
apples = 29
kids = 3
apples
It evaluates to whatever value was assigned to apples
.
apples / kids
It expresses how many apples we should give each kid to divide them evenly.
We don’t have to know the values that have been assigned to apples
or kids
to understand what this expression means.
The computer can evaluate it (assuming it does know the appropriate values).
Translating what we mean into expressions
Understanding the meaning of expressions in code