pow(base, exp, mod=None)

Returns the result of raising a number to a power, with optional modular division.

Parameters

The pow() function accepts three parameters:

  • base - the base value to be raised to a power
  • exp - the exponent value
  • mod - (optional) divides the result of base raised to exp and finds the remainder: base**exp % mod

Arguments of numeric types are expected. If operands of different types are passed, type conversion occurs according to binary arithmetic rules. Using only the first two arguments, pow(base, exp), is equivalent to using the exponentiation operator: base ** exp. The three-argument form is used for modular exponentiation.

Return Value

The pow() function returns:

  • base**exp - when no modulus is provided
  • base**exp % mod - when the modulus argument is provided
  • 1 - if the exponent is 0
  • 0 - if the base is 0

Examples

pow(2, 3)  # 8
pow(10, 2)  # 100

pow(10, -2)  # 0.01

pow(2, 3, 10)  # 8