The pow() function is one of Python's built-in functions, used for fast exponentiation and modular exponentiation.
Function Syntax
This function exists in two forms:
1. Calculate x raised to the power of y, same result as x**y:
pow(x, y)
2. Calculate (x**y) % z (modular exponentiation):
pow(x, y, z)
The pow() function internally uses fast exponentiation algorithms, offering significantly better performance than x**y and (x**y) % z.
pow() Function Examples
# Integer exponentiation
print(pow(2, 3)) # 8 (2³)
print(pow(5, 2)) # 25 (5²)
print(pow(10, 0)) # 1 (any number to power 0)
# Negative exponent
print(pow(2, -2)) # 0.25 (2⁻² = 1/4)
print(pow(10, -1)) # 0.1
# Decimal exponent
print(pow(4, 0.5)) # 2.0 (square root)
print(pow(8, 1/3)) # 2.0 (cube root)
print(pow(9, 1.5)) # 27.0 (9^(3/2))
# Modular exponentiation: calculate (x**y) % z
print(pow(2, 3, 5)) # 3
print(pow(5, 2, 7)) # 4
print(pow(10, 3, 13)) # 12