diff --git a/docs/builtin/pow.md b/docs/builtin/pow.md index 7ac7d14b..298ca6c6 100644 --- a/docs/builtin/pow.md +++ b/docs/builtin/pow.md @@ -1,6 +1,6 @@ --- title: Python pow() built-in function - Python Cheatsheet -description: Given a string representing one Unicode character, return an integer representing the Unicode code point of that character. +description: The pow() function returns the power of a number. --- @@ -12,16 +12,27 @@ Python pow() built-in function From the Python 3 documentation - Given a string representing one Unicode character, return an integer representing the Unicode code point of that character. + The pow() function returns the power of a number.It takes two or three arguments: + pow(base, exp): Returns base raised to the power of exp (base ** exp). + pow(base, exp, mod): Returns (base ** exp) % mod (for modular arithmetic). + Result is computed more efficiently than base ** exp % mod, if mod arg is present. ## Example ```python ->>> result = pow(2, 3) ->>> print(result) +# Basic exponentiation +>>> pow(2, 3) # 8 + +# Using three arguments (modular exponentiation) +>>> pow(2, 3, 5) +# 3 (since 2^3 = 8, and 8 % 5 = 3) + +# Works with negative exponents (returns float) +>>> pow(2, -3) +# 0.125 (since 2^(-3) = 1/8) ```