![]() |
VOOZH | about |
pow() function in Python is a built-in tool that calculates one number raised to the power of another. It also has an optional third part that gives the remainder when dividing the result. Example:
9
Explanation: pow(3, 2) calculates 32 = 9, where the base is positive and the exponent is positive.
pow(x, y, mod)
Parameters:
Returns: It returns the value x**y in float or int (depending upon input operands or 2nd argument).
The below table summarizes the different cases to apply the Python pow() function.
Example 1: In this example, we are using the third argument in the pow() function, which performs a modulus operation after calculating the power.
1
Explanation: print(pow(3, 4, 10)) calculates 34 mod 10. First 34=81, then finds the remainder when 81 is divided by 10, which is 1.
Example 2: In this example, we use the pow() function to demonstrate how it handles different combinations of positive and negative bases and exponents, resulting in varying outputs based on their signs.
64 -64 0.015625 -0.015625
Explanation: