File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change 1
1
---
2
2
title : Python pow() built-in function - Python Cheatsheet
3
- description : Given a string representing one Unicode character, return an integer representing the Unicode code point of that character .
3
+ description : The pow() function returns the power of a number .
4
4
---
5
5
6
6
<base-title :title =" frontmatter.title " :description =" frontmatter.description " >
@@ -12,16 +12,27 @@ Python pow() built-in function
12
12
From the <a target="_blank" href="https://docs.python.org/3/library/functions.html#pow">Python 3 documentation</a>
13
13
</base-disclaimer-title >
14
14
<base-disclaimer-content >
15
- Given a string representing one Unicode character, return an integer representing the Unicode code point of that character.
15
+ The pow() function returns the power of a number.It takes two or three arguments:
16
+ pow(base, exp): Returns base raised to the power of exp (base ** exp).
17
+ pow(base, exp, mod): Returns (base ** exp) % mod (for modular arithmetic).
18
+ Result is computed more efficiently than base ** exp % mod, if mod arg is present.
16
19
</base-disclaimer-content >
17
20
</base-disclaimer >
18
21
19
22
## Example
20
23
21
24
``` python
22
- >> > result = pow ( 2 , 3 )
23
- >> > print (result )
25
+ # Basic exponentiation
26
+ >> > pow ( 2 , 3 )
24
27
# 8
28
+
29
+ # Using three arguments (modular exponentiation)
30
+ >> > pow (2 , 3 , 5 )
31
+ # 3 (since 2^3 = 8, and 8 % 5 = 3)
32
+
33
+ # Works with negative exponents (returns float)
34
+ >> > pow (2 , - 3 )
35
+ # 0.125 (since 2^(-3) = 1/8)
25
36
```
26
37
27
38
You can’t perform that action at this time.
0 commit comments