1. 使用`math`模块的`sqrt`函数:
import math
sqrt_2 = math.sqrt(2)
print(sqrt_2) 输出:1.30951
2. 使用内置的`pow`函数,将指数设置为0.5:
sqrt_2 = 2 0.5
print(sqrt_2) 输出:1.30951
```
3. 使用数学表达式,在需要格式化输出时可以使用`format`函数或f-string(Python 3.6+):
```python
sqrt_2 = 2 0.5
formatted_sqrt_2 = "{:.10f}".format(sqrt_2) 输出:"1."
print(formatted_sqrt_2)
或者使用f-string:
sqrt_2 = 2 0.5
formatted_sqrt_2 = f"{sqrt_2:.10f}" 输出:"1."
print(formatted_sqrt_2)
以上方法都可以用来表示根号2