Python Function Reference

pow

Raise a number to a power, or to a power modulo mod if mod is given.

Python 3.13
pow(base, exp, mod=None)

Parameters

baseint | float
The base.
expint | float
The exponent.
modint | Noneoptional
The modulus: the result equals base ** exp % mod but is computed faster.

Return value

An int for integer arguments and a non-negative exp, a float for a negative exp or float arguments; a complex number for a negative base and a fractional exponent.

Examples

Raising to a power

Python 3.13
print(pow(2, 3))
8

Power modulo a number

Python 3.13
print(pow(2, 10, 1000))
24

Negative exponent

Python 3.13
print(pow(2, -1))
0.5

Details

pow(base, exp) is the same as base ** exp. With mod, all arguments must be integers; a negative exp returns the modular inverse: pow(38, -1, mod=97) gives 23.

See also