1. 使用 ` ` 运算符:
```python
x = 2
result = x 2
print(result) 输出:4
2. 使用 `math.pow()` 函数:
import math
x = 2
result = math.pow(x, 2)
print(result) 输出:4
3. 使用乘法运算符 `*`:
x = 2
result = x * x
print(result) 输出:4
以上任何一种方法都可以用来计算一个数的平方。您可以根据自己的需要和代码的上下文选择最合适的方法