Sub topic 3
What an exponent means
This chapter assumes you can multiply whole numbers and know what a fraction and a negative integer are. It covers only what an exponent means and where it sits in an expression. The full order of operations, negative bases, and zero and negative exponents get their own chapters.
Repeated multiplication
An exponent is a small raised number that tells you how many times to use a number as a factor. In 3^4, the base is 3 and the exponent (also called the power) is 4. The whole expression is read "3 to the fourth power".
3^4 = 3 × 3 × 3 × 3 = 81The exponent counts the copies of the base that are multiplied together. It does not multiply the base by the exponent. That distinction is the most common beginner error.
| Expression | Meaning | Value |
|---|---|---|
| `2^5` | 2 × 2 × 2 × 2 × 2 | 32 |
| `5^2` | 5 × 5 | 25 |
| `10^3` | 10 × 10 × 10 | 1000 |
| `1^7` | 1 × 1 × 1 × 1 × 1 × 1 × 1 | 1 |
| `7^1` | 7 (one copy) | 7 |
Two names are worth knowing. x^2 is "x squared" and x^3 is "x cubed". These come from the area of a square and the volume of a cube. Higher powers are just "to the fourth", "to the fifth", and so on.
print(3 ** 4) # 81: four copies of 3 multiplied together
print(3 * 4) # 12: this is ordinary multiplication, a different operation
print(2 ** 10) # 1024: powers grow quicklyThe code uses ** for exponents. In Python, the ^ symbol means something else (bitwise XOR), so 3 ^ 2 gives 1, not 9.
Order matters: the base and the exponent
Swapping the base and the exponent usually changes the value.
2^3 = 2 × 2 × 2 = 83^2 = 3 × 3 = 9
Exponentiation is not commutative, unlike addition and multiplication. Only a few pairs give the same result, such as 2^4 and 4^2, which are both 16. Do not rely on that coincidence.
An exponent attaches to the thing directly before it
The exponent applies only to the base immediately to its left. If the base is a single number, the exponent acts on that number alone. If the base is a parenthesized group, the exponent acts on the whole group's value.
print(2 * 3 ** 2) # 18: only the 3 is squared (9), then 2 * 9
print((2 * 3) ** 2) # 36: the group is evaluated first (6), then squared
print(2 + 3 ** 2) # 11: 3 is squared first, then added to 2
print((2 + 3) ** 2) # 25: 5 squaredThis is the first place the order of operations appears. An exponent binds more tightly than multiplication or addition. It is done before them unless parentheses say otherwise. The later chapters build this into the full hierarchy.
Evaluating an exponent inside a larger expression
Work in this order for an exponent inside a larger expression:
- Find each exponent and identify its base. If the base is in parentheses, evaluate the parentheses first.
- Replace the base-and-exponent pair with its value.
- Continue with the remaining operations.
Take 5 + 2 · 3^2:
- The exponent has base 3, so
3^2 = 9. - The expression becomes
5 + 2 · 9. - Multiplication comes before addition:
5 + 18 = 23.
print(5 + 2 * 3 ** 2) # 23If you wrongly multiplied first, you would compute 2 · 3 = 6, then 6^2 = 36, then 5 + 36 = 41. The correct answer is 23, and the difference comes entirely from what the exponent attaches to.
Exponents with fractions and other bases
A fraction raised to a power needs parentheses, because the exponent must apply to the whole fraction.
(2/3)^2 = (2/3) × (2/3) = 4/9Both the numerator and the denominator are raised to the power. Without the parentheses, 2/3^2 would mean 2 divided by 3^2, which is 2/9. A later chapter covers powers of fractions in full, so here it is enough to see that the exponent counts copies of the whole base.
from fractions import Fraction
print(Fraction(2, 3) ** 2) # 4/9: both parts of the fraction are squared
print(Fraction(2, 3 ** 2)) # 2/9: only the denominator is squaredExponents are not distributive over addition
A frequent mistake is to push an exponent through a sum. With a = 2 and b = 3:
(a + b)^2 = 5^2 = 25a^2 + b^2 = 4 + 9 = 13
These are different. Expanding (a + b)^2 means writing it as (a + b) × (a + b), which gives extra cross terms. The exponent distributes over multiplication, so (a · b)^2 = a^2 · b^2. With a = 2 and b = 3 that is 36 = 4 · 9.
a, b = 2, 3
print((a + b) ** 2) # 25
print(a ** 2 + b ** 2) # 13: not equal to the line above
print((a * b) ** 2) # 36
print(a ** 2 * b ** 2) # 36: equal, because the exponent distributes over multiplicationCommon errors
- Multiplying base by exponent.
4^3is 64, not 12. Write out the repeated factors if unsure. - Applying the exponent too widely. In
2 · 3^2, the exponent does not square the 2 as well. Only the base to its left is squared. - Applying the exponent too narrowly. In
(2 · 3)^2, the whole group is the base, so the result is 36, not 18. - Splitting a sum.
(a + b)^2is nota^2 + b^2. - Using
^in Python. Use**.
Practice
Exercise
Evaluate 4 + 3 · 2^3 − 5 by hand. Identify the base and exponent first, then check your answer with Python.
Show answer
The base is 2 and the exponent is 3, so 2^3 = 2 × 2 × 2 = 8. The expression becomes 4 + 3 · 8 − 5. Multiplication comes next: 4 + 24 − 5. Then work left to right: 28 − 5 = 23. In Python, print(4 + 3 2 * 3 - 5) prints 23.
Exercise
For a = 1 and b = 2, compute (a + b)^2 and a^2 + b^2. Are they equal? Then compute (a · b)^2 and a^2 · b^2.
Show answer
(a + b)^2 = 3^2 = 9, while a^2 + b^2 = 1 + 4 = 5, so they are not equal. For multiplication, (a · b)^2 = 2^2 = 4 and a^2 · b^2 = 1 · 4 = 4, so they are equal. The exponent distributes over multiplication but not over addition.