Summary: In this tutorial, we will learn about Python's built-in function pow() with the help of examples.
The pow(x, y) function in Python is used to find the value of x raised to the power of y (xy).
The Syntax for pow() is:
pow(x, y, z)
Parameters
| Parameter | Condition | Description |
|---|---|---|
| x | Required | Base |
| y | Required | Exponent |
| z | Optional | Modulus |
The third parameter (z) is optional, but when specified pow() function returns xy%z.
Examples using pow()
>>> pow(2,4)
16
We can also achieve the above result by using 2**4 in Python.
>>> pow(2+3j, 3)
-46+9j
Example of pow() when all 3 parameters are specified.
>>> pow(2,4,6)
4
Here the output is four because 16%6=4
When y parameter is negative, pow() returns a float number as the result.
>>> pow(2, -4)
0.0625