From fbe2fde8907322d0ff7556c6db1bf785815de92b Mon Sep 17 00:00:00 2001 From: Gaurav Pagare <86569240+gspagare@users.noreply.github.com> Date: Sat, 29 Mar 2025 20:25:00 +0530 Subject: [PATCH 1/5] Update pow.md Now the description as well as the content, and code example has been corrected --- docs/builtin/pow.md | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/docs/builtin/pow.md b/docs/builtin/pow.md index 7ac7d14b..ead8fc0d 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 (i.e., base ** exp). + pow(base, exp, mod): Returns (base ** exp) % mod (useful for modular arithmetic). + If the optional mod argument is present, the result is computed more efficiently than base ** exp % mod. ## 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) ``` From 93c2193678c54e309204cb715885cf3805058e1c Mon Sep 17 00:00:00 2001 From: Gaurav Pagare <86569240+gspagare@users.noreply.github.com> Date: Sat, 29 Mar 2025 20:33:22 +0530 Subject: [PATCH 2/5] Update pow.md Corrected the description, and content of the pow function, as well as updated with a better code, also fixed the line length issue in pow.md --- docs/builtin/pow.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/builtin/pow.md b/docs/builtin/pow.md index ead8fc0d..31091536 100644 --- a/docs/builtin/pow.md +++ b/docs/builtin/pow.md @@ -12,10 +12,12 @@ Python pow() built-in function From the Python 3 documentation - 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 (i.e., base ** exp). - pow(base, exp, mod): Returns (base ** exp) % mod (useful for modular arithmetic). - If the optional mod argument is present, the result is computed more efficiently than base ** exp % mod. + 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). + If the optional mod argument is present, the result is computed more + efficiently than base ** exp % mod. From 215b103c5a436eee59bdad8b66f3a15fab9ef94f Mon Sep 17 00:00:00 2001 From: Gaurav Pagare <86569240+gspagare@users.noreply.github.com> Date: Sat, 29 Mar 2025 20:42:22 +0530 Subject: [PATCH 3/5] Update pow.md Corrected the description, and content of the pow function, as well as updated with a better code, also fixed the line length issue and indentation issue in pow.md --- docs/builtin/pow.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/builtin/pow.md b/docs/builtin/pow.md index 31091536..69e59f19 100644 --- a/docs/builtin/pow.md +++ b/docs/builtin/pow.md @@ -13,11 +13,11 @@ Python pow() built-in function 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). - If the optional mod argument is present, the result is computed more - efficiently than base ** exp % mod. + 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). + If the optional mod argument is present, the result is computed more + efficiently than base ** exp % mod. From 1699a17bdf83214f87d95a5c19a7884e346942bb Mon Sep 17 00:00:00 2001 From: Gaurav Pagare <86569240+gspagare@users.noreply.github.com> Date: Sat, 29 Mar 2025 20:48:20 +0530 Subject: [PATCH 4/5] Update pow.md Corrected the description, and content of the pow function, as well as updated with a better code, also fixed the line length issue in pow.md --- docs/builtin/pow.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/docs/builtin/pow.md b/docs/builtin/pow.md index 69e59f19..495f4989 100644 --- a/docs/builtin/pow.md +++ b/docs/builtin/pow.md @@ -12,12 +12,11 @@ Python pow() built-in function From the Python 3 documentation - 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). - If the optional mod argument is present, the result is computed more - efficiently than base ** exp % mod. + 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). + If the optional mod argument is present, the result is computed more + efficiently than base ** exp % mod. From 6d63483a84ce987cf42906fab340129dc6ce91b3 Mon Sep 17 00:00:00 2001 From: Gaurav Pagare <86569240+gspagare@users.noreply.github.com> Date: Sat, 29 Mar 2025 20:54:38 +0530 Subject: [PATCH 5/5] Update pow.md Corrected the description, and content of the pow function, as well as updated with a better code, also fixed the line length issue and indentation issue in pow.md --- docs/builtin/pow.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/builtin/pow.md b/docs/builtin/pow.md index 495f4989..298ca6c6 100644 --- a/docs/builtin/pow.md +++ b/docs/builtin/pow.md @@ -12,11 +12,10 @@ Python pow() built-in function From the Python 3 documentation - 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). - If the optional mod argument is present, the result is computed more - efficiently than base ** exp % mod. + 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.