整数与浮点数的除法
Python 提供两种除法运算符:/ 和 //。在 Python 3 中,/ 始终返回浮点数结果,而 // 是地板除(floor division),始终返回整数结果。地板除等同于执行 math.floor(numerator/divisor),它会返回小于或等于除法结果的最大整数。您可以在 Python 文档 中了解更多关于 math.floor 的信息。
本练习是课程的一部分
Python 的数据类型
练习说明
- 打印
2/1和1/2的结果。 - 打印
2//1和1//2的地板除结果。 - 打印
2/1和2//1的类型。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Print the result of 2/1 and 1/2
print(____)
print(____)
# Print the floored division result of 2//1 and 1//2
print(____)
print(____)
# Print the type of 2/1 and 2//1
print(____)
print(____)