On this page
  1. pow
  2. Import & Availability
  3. Overview & Signature
  4. Usage
  5. Gotchas
  6. REPL Inspect

pow

Prev: ord | Up: __builtins__ | Next: print
Rel: abs, divmod, max, min, round
Ref: docs.python.org — pow
Tags: #public #python3 #builtins


Import & Availability

# Built-in (available globally without import)
from builtins import pow

Overview & Signature

pow(base, exp, mod=None)

Equivalent to baseexp with 2 arguments or baseexp % mod with 3 arguments Some types, such as ints, are able to use a more efficient algorithm when invoked using the three argument form.

Usage

assert pow(2, 10) == 1024
# 3-argument modular exponentiation: (base ** exp) % mod in O(log exp) time!
assert pow(2, 10, 1000) == 24
assert pow(3, -1, 11) == 4   # modular inverse: (3 * 4) % 11 == 1

Gotchas

REPL Inspect

help(pow)

Linked from

Related notes