1. 使用内置函数 `abs()`:
```python
x = -10
absolute_number = abs(x)
print(absolute_number) 输出:10
2. 使用 `math` 模块中的 `math.fabs()` 函数:
```python
import math
x = -3.14
absolute_number = math.fabs(x)
print(absolute_number) 输出:3.14
3. 使用 `numpy` 库中的 `np.abs()` 函数(适用于数组和标量):
```python
import numpy as np
x = np.array([-10, 0, 10])
absolute_number = np.abs(x)
print(absolute_number) 输出:[10 0 10]
以上方法都可以用来计算一个数的绝对值