在Python中,要输出一个数的平方,你可以使用 ` ` 运算符。下面是一个简单的示例代码:
```python
定义一个变量并赋值
x = 5
使用 运算符计算平方
square = x 2
输出结果
print(square)
运行上述代码,输出结果为 `25`,因为 `5` 的平方是 `25`。
你还可以使用 `math` 模块中的 `pow` 函数来计算平方,如下所示:
```python
导入math模块
import math
定义一个变量并赋值
x = 5
使用math.pow函数计算平方
square = math.pow(x, 2)
输出结果
print(square)
这段代码的输出结果同样是 `25`。