在Python中,如果你想计算对数,可以使用`math`模块中的`log`函数。以下是使用`math.log`函数计算对数的基本语法:
```python
import math
计算自然对数(底数为e)
result = math.log(x)
计算以10为底的对数
result = math.log10(x)
计算以2为底的对数
result = math.log2(x)
其中`x`是你想计算对数的数值,`base`是可选参数,表示对数的底数,如果不指定,则默认为自然对数(底数为`e`)。
例如,要计算`100`的自然对数,你可以这样写:
```python
import math
result = math.log(100)
print(result) 输出结果大约为 4.7352