Exercises · Q4
Q.How is built-in function pow() function different from function math.pow() ? Explain with an example.
Tripura TbseTextbookSubjective· 3mImportance★★★★★est
55% · 22/40 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Both raise a number to a power, but built-in pow() works with exact integers, needs no import and offers a three-argument modular form, while math.pow() always converts to float, returns a float, and takes exactly two arguments.
The idea. Python has two exponentiation functions because they serve different domains: the built-in pow() is general-purpose (integer-exact, and with the pow(base, exp, mod) form used in number theory), whereas math.pow() belongs to the C-style floating-point library — everything in the math module speaks float.
import math
print(pow(2, 10)) # built-in: int result
print(math.pow(2, 10)) # math module: float result
print(pow(5, 2, 3)) # three-argument form: (5**2) % 3
Expected output
1024
1024.0
1
The differences, side by side
built-in pow() | math.pow() | |
|---|---|---|
| Import needed | no | yes (import math) |
pow(2, 10) | 1024 (int, exact) | 1024.0 (float) |
| Return type | int for int args, float otherwise | always float |
| Third argument | yes — pow(a, b, m) = a to the power b, modulo m | no — TypeError |
| Very large integers | exact (unlimited precision) | rounded to float precision |
- The three-argument call
pow(5, 2, 3)computes 5² = 25, then 25 mod 3 = 1, efficiently — handy in cryptography-style computations.math.pow(5, 2, 3)raisesTypeError: math.pow() takes exactly 2 arguments (3 given). …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.