使用要点
- 每一步打印都带着自己的标签:
5 % 3:、fmod(5, 3):、remainder(5, 3):。
常见问题
运行前要先安装什么?
什么都不用额外装——运行时自带了代码所需的一切。 全部导入都来自标准库:math。
代码示例
import math
print("5 % 3:", 5 % 3)
print("fmod(5, 3):", math.fmod(5, 3))
print("remainder(5, 3):", math.remainder(5, 3))
# % follows the sign of the divisor, math.fmod follows the sign of the dividend
print("-5 % 3:", -5 % 3)
print("fmod(-5, 3):", math.fmod(-5, 3))
print("remainder(-5, 3):", math.remainder(-5, 3))
# remainder rounds to the nearest integer multiple: the result lands in [-y/2, y/2]
print("remainder(4, 3):", math.remainder(4, 3))
print("remainder(6, 3):", math.remainder(6, 3))