Module 4 · Operators — topic 8 of 16
Exponentiation
The ** operator raises a number to a power. Learn integer, negative and fractional exponents, pow() with a modulus, right-to-left grouping and practical formulas such as compound interest.
Learning objectives
- Raise numbers to powers with **
- Use fractional exponents for roots
- Understand ** precedence with unary minus
Definition
The ** operator raises a number to a power. Learn integer, negative and fractional exponents, pow() with a modulus, right-to-left grouping and practical formulas such as compound interest.
Introduction
Exponentiation multiplies a number by itself a given number of times. 2 ** 5 means 2 × 2 × 2 × 2 × 2, which is 32. Python uses ** rather than the ^ symbol you may have seen elsewhere.
Why it matters
Squares and cubes appear in geometry, powers of two in computing, and exponential growth in finance and science. Fractional exponents give square roots and cube roots without importing anything.
Detailed explanation
Positive integer exponents give exact integers: 3 ** 4 is 81, and Python handles huge results such as 2 ** 1000 exactly.
A negative exponent gives a reciprocal: 2 ** -2 is 0.25, always a float.
A fractional exponent gives a root: 16 ** 0.5 is 4.0 (square root) and 27 ** (1/3) is about 3.0.
** is right-associative: 2 ** 3 ** 2 is 2 ** 9 = 512, not 8 ** 2 = 64.
** binds more tightly than unary minus on its left: -3 ** 2 is -9. Write (-3) ** 2 to get 9.
pow(base, exp) is the same as base ** exp. pow(base, exp, mod) efficiently computes the remainder of a huge power, used in cryptography.
Exponentiation grows extremely fast. Doubling every step means 2 ** 10 is about a thousand and 2 ** 30 is about a billion. This is why algorithms whose work doubles with each extra item, which you will meet in Module 18, quickly become impractical.
Syntax
- base ** exponent raises base to the power exponent.
- A fractional exponent gives a root.
- pow() with three arguments computes (base ** exponent) % modulus efficiently.
Code examples
Powers and roots
1024 125 0.25 9.0
Precedence surprises
-9 9 512
More examples
Compound interest and modular powers
After 5 years: Rs 73,466.40 Square area: 49 Cube volume: 343 Last digit of 7**2026: 9
Step-by-step explanation
- (1 + rate) ** years grows the amount by 8% each year for 5 years.
- The :,.2f format adds thousands separators and two decimals.
- side ** 2 and side ** 3 give area and volume.
- pow(7, 2026, 10) finds the last digit of a huge number without computing it fully.
Expected output
Running “Compound interest and modular powers” prints exactly:
Practical applications
- Banks compute compound interest with **.
- Computer memory sizes are powers of two, such as 2 ** 30 bytes in a gibibyte.
- Encryption algorithms use pow() with a modulus on very large numbers.
Best practices
- Use parentheses with negative bases.
- Use math.sqrt() when it reads more clearly than ** 0.5.
- Use pow(b, e, m) for modular powers of large numbers.
Common mistakes
Using ^ for powers
Avoid
Prefer
^ is bitwise XOR in Python.
Squaring a negative without parentheses
Avoid
Prefer
** is applied before the unary minus.
Key takeaways
- ** raises a number to a power; ^ is not a power operator.
- Negative exponents give reciprocals; fractional exponents give roots.
- ** is right-associative and binds tighter than unary minus.
Try it yourself
- 1Print the first ten powers of 2 using a loop and **.
- 2Calculate the hypotenuse of a right triangle with sides 9 and 12 using ** 0.5.
Finished reading? Mark it complete to update your dashboard.
Suggested practice
1 question test this exact topic. Answers and explanations are revealed after you submit.
- BeginnerWhat is printed?