在Python中,表示根号(平方根)可以通过以下几种方法:
1. 使用`math`模块的`sqrt`函数:
import math
result = math.sqrt(25)
print(result) 输出:5.0
2. 使用幂运算符` `:
```python
result = 16 0.5
print(result) 输出:4.0
3. 使用`cmath`模块的`sqrt`函数(用于复数):
import cmath
result = cmath.sqrt(-25)
print(result) 输出:5j
4. 使用`numpy`库的`sqrt`函数:
import numpy as np
result = np.sqrt(25)
print(result) 输出:5.0
以上方法均可用于计算平方根,选择哪一种取决于你的具体需求和应用场景