In Python, the pow function serves the purpose of calculating the exponentiation of a number. When a third argument (z) is provided, it computes x raised to the power of y, followed by taking the modulus with z, expressed as (x, y) % z.
Python pow Function Syntax
It has the following syntax:
pow(x, y, z)
Parameters
It has the following parameters:
- x: It is a number, a base
- y: It is a number, an exponent.
- z (optional): It is a number and the modulus.
Return
It computes x raised to the power of y, and then takes the result modulo z, provided that a third parameter (z) is specified, which can be expressed as (x, y) % z.
Different Examples for Python pow Function
In this section, we will explore various instances of the Python pow function.
Python pow Function Example
The following example illustrates how the pow function operates in Python.
# positive x, positive y (x**y)
print(pow(4, 2))
# negative x, positive y
print(pow(-4, 2))
# positive x, negative y (x**-y)
print(pow(4, -2))
# negative x, negative y
print(pow(-4, -2))
Output:
16
16
0.0625
0.0625
Clarification: In the preceding example, we have utilized various values for the parameters (x, y), which computes x raised to the power of y.
Python pow Function Example
The following example demonstrates the usage of pow with three parameters (x, y, z)
x = 4
y = 7
z = 3
print(pow(x, y, z))
Output: