Tutorial Study Image

Python pow()

Python pow() function helps to estimate the powers of a given number. It returns the first argument(x) to the power of the second one(y) if a third argument(z) is present, it is given as modulus z i.e. (x, y) % z.

pow(x, y, z) #where x & y are numbers showing base and exponent

pow() Parameters:

Takes three parameters. In this first two parameter is present (pow(x,y)) which is equal to xy,  if it has three parameters (pow(x,y,z))  which is equal to xy % z

Parameter Description Required / Optional
x a number, the base Required
y a number, the exponent Required
z a number, used for modulus optional

pow() Return Value

If z is present, x and y must be of integer types, and y must be non-negative.

Input Return Value
 integer return power

Examples of pow() method in Python

Example 1: Python pow() method working

# positive x, positive y (x**y)
print(pow(2, 2))    # 4

# negative x, positive y
print(pow(-2, 2))    # 4  

# positive x, negative y
print(pow(2, -2))    # 0.25

# negative x, negative y
print(pow(-2, -2))    # 0.25



Example 2:pow() with three arguments (x**y) % z

x = 7
y = 2
z = 5

print(pow(x, y, z))    # 4