Chapter #7 – Functions

Chapter #7 – Q #4
How is built-in function pow() function different from function math.pow() ? Explain with an example.
The built-in pow() function and the math.pow() function in Python serve similar purposes—raising a number to a power—but they have key differences in behavior, performance, and return types.
Differences Between pow() and math.pow()
Return Type
pow(): This built-in function can return an integer if both arguments are integers. It can also take an optional third argument for modulo operation, allowing for calculations like pow(x,y,z) ≡ (xy) mod z
math.pow(): This function always returns a float, regardless of whether the inputs are integers or floats. It does not support the modulo operation.
Example:
import math
# Using built-in pow()
result1 = pow(2, 3) # Returns 8 (integer)
result2 = pow(2, 3, 5) # Returns 3 (8 % 5)
result3 = pow(2.0, 3.0) # Returns 8.0 (float)
# Using math.pow()
result4 = math.pow(2, 3) # Returns 8.0 (float)
result5 = math.pow(2.0, 3.0) # Returns 8.0 (float)
NCERT Computer Science Class 11 Chapter 7 Solutions Q 4