pow() Power
Last updated: 2026-09-22
pow() Power
pow(base, exp[, mod]) returns base**exp; the 3-arg form does modular exponentiation efficiently.
| Category | Built-in Functions |
|---|---|
| Kind | Built-in Function |
| Python Version | all |
📝 Syntax
pow(base, exp[, mod])
⚙️ Parameters
| base Required | The base (a numeric type). |
|---|---|
| exp Required | The exponent (a numeric type). |
| mod Optional | Modulus; when given, computes base**exp % mod efficiently.(Default:None) |
Returns:base**exp, or (base**exp) % mod when mod is given.
💥 Raises
TypeError— Raised when the operand types do not support exponentiation (e.g. strings).ValueError— Raised when base is negative, exp is negative and mod is given.OverflowError— Raised when the result is too large to compute (memory limit).
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
1024
0.125
1
🏷️ Related Built-in Functions
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QAre pow(2, 10) and 2 ** 10 the same?
AThe result is the same (1024). But ** has no three-argument form, while pow(base, exp, mod) computes (base**exp) % mod with fast modular exponentiation, which is noticeably more efficient for large numbers.
QWhat does pow(2, -3) return?
AIt returns 0.125 — a negative exponent yields the floating-point reciprocal, equivalent to 1 / (2**3).
QHow is pow(3, 4, 5) computed?
AFirst 3**4 = 81, then modulo 5 gives 1, equivalent to 81 % 5; however the three-argument form never constructs a huge intermediate result, making it ideal for modular exponentiation of large numbers like RSA.
QWhy does pow(-2, -3, 5) raise a ValueError?
AA negative base combined with a negative exponent cannot define a unique result under modular arithmetic, so Python raises a ValueError; avoid combining a negative base, a negative exponent, and mod.