Built-in Functions and Types

pow()

Raise a base to a power, optionally reducing modulo an integer. Without a modulus the behavior follows **, including a float for negative integer exponents and complex results for negative real bases with nonintegral exponents. For ordinary integer operands the modular form avoids building the full power. A negative modular exponent requires an invertible base modulo mod; zero modulus or a missing inverse raises ValueError.

Formal Syntax & Structure

python syntaxpython
pow(base, exp, mod=None)

Parameters & Attributes

NameTypeDescription
basenumberBase of the power.
expnumberExponent; must be integer for ordinary modular calculation.
modint | NoneNonzero integer modulus for ordinary integer operands; None selects normal exponentiation.

Return Value

number

Power or modular result; integer for the ordinary three-integer form.

Working Example

Example Snippetpython
print(pow(3, 5))print(pow(3, 5, 7))print(pow(3, -1, 7))
Python Reference