1. 使用 ` ` 运算符:
```python
x = 5
square = x 2
print(square) 输出:25
2. 使用 `math.pow()` 函数(需要先导入 `math` 模块):
```python
import math
x = 5
square = math.pow(x, 2)
print(square) 输出:25
3. 使用 `pow()` 函数(内置函数,用法与 ` ` 运算符类似):
```python
x = 5
square = pow(x, 2)
print(square) 输出:25
以上方法都可以用来计算一个数的平方。选择哪种方法取决于你的具体需求和代码风格