On this page
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
- Always use 3-arg
pow(base, exp, mod)for modular arithmetic/crypto: Computing(base ** exp) % moddirectly is astronomically slower and blows up memory.
REPL Inspect
help(pow)
Linked from
- tuts/python3/__builtins__
- tuts/python3/__builtins__/__builtins__
- tuts/python3/__builtins__/abs
- tuts/python3/__builtins__/divmod
- tuts/python3/__builtins__/max
- tuts/python3/__builtins__/min
- tuts/python3/__builtins__/ord
- tuts/python3/__builtins__/print
- tuts/python3/__builtins__/round
- tuts/python3/__builtins__/sum
Related notes
- tuts/python3/__builtins__/__builtins__ Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/abs Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/divmod Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/max Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/min Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/ord Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/print Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/round Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__ links to this page; shared tags: #builtins
- tuts/python3/__builtins__/sum links to this page; shared tags: #builtins