wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

How is built-in function pow() function different from function math.pow()? Explain with an example.

Open in App
Solution

There are two main differences between built-in pow() function and math.pow() functions.
  • The built-in pow(x,y [,z]) function has an optional third parameter as modulo to compute x raised to the power of y and optionally do a modulo (% z) on the result. It is same as the mathematical operation: (x ^ y) % z. Whereas, math.pow() function does not have modulo functionality.
  • In math.pow(x,y) both 'x' and 'y' are first converted into 'float' data type and then the power is calculated. Therefore, it always returns a value of 'float' data type. This does not happen in the case of built-in pow function, however, if the result is a float data type, the output will be float else it will return integer data type.
Example:
import math
print()
#it will return 25.0 i.e float
print(math.pow(5,2))
print()
#it will return 25 i.e int
print(pow(5,2))

flag
Suggest Corrections
thumbs-up
3
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Language is a Pattern
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon