在Python中,计算一个数的次方可以使用 ` ` 运算符。例如,要计算 `2` 的 `3` 次方,可以写为 `2 3`。
```python
计算 2 的 3 次方
result = 2 3
print(result) 输出:8
计算 3 的 2 次方
result = 3 2
print(result) 输出:9
计算 2 的 3 次方加上 3 的 2 次方
result = 2
3 + 3 2print(result) 输出:13
另外,Python还提供了 `pow()` 函数来计算次方,该函数接受两个参数 `x` 和 `y`,并返回 `x` 的 `y` 次方的值。例如:
```python
import math
使用 pow() 函数计算 100 的 2 次方
result = math.pow(100, 2)
print(result) 输出:10000