pow() Function - Python
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:
print(pow(3,2))
Output
9
Explanation: pow(3, 2) calculates 32 = 9, where the base is positive and the exponent is positive.
Syntax of pow() function
pow(x, y, mod)
Parameters:
- x : Number whose power has to be calculated.
- y : Value raised to compute power.
- mod [optional]: if provided, performs modulus of mod on the result of x**y (i.e.: x**y % mod)
Returns: It returns the value x**y in float or int (depending upon input operands or 2nd argument).
Implementation cases in pow() function
The below table summarizes the different cases to apply the Python pow() function.

Examples of 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.
print(pow(3, 4, 10))
Output
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.
# +x, +y
print(pow(4, 3))
# -x, +y
print(pow(-4, 3))
# +x, -y
print(pow(4, -3))
# -x, -y
print(pow(-4, -3))
Output
64 -64 0.015625 -0.015625
Explanation:
- pow(4, 3) calculates 43=64, where both the base and exponent are positive.
- pow(-4, 3) calculates (−4)3=-64, where the base is negative and the exponent is positive.
- pow(4, -3) computes 1/43= 0.015625, where the base is positive and the exponent is negative.
- pow(-4, -3) calculates 1/(−4)3= -0.015625, where both the base and exponent are negative.