math.remainder(x, y)

本页内容
上一节: Ref_math_radians 下一节: Ref_math_sin

Python math.remainder() 方法

Python math 模块

Python mathremainder(x, y) 方法返回 x/y 的余数。

Python 版本:3.7

语法

math.remainder() 方法语法如下:


示例

math.remainder(x, y)

参数说明:

  • x -- 必需,被除数。
  • y -- 可选,除数。必须是非零数字,否则会发生 ValueError。

返回值

一个浮点值,返回余数。

==

以下实例计算余数:


示例

# 导入 math 包

import math

# x/y 的余数

print (math.remainder(9, 2))

print (math.remainder(9, 3))

print (math.remainder(18, 4))

print (math.remainder(23.5, 5))

print (math.remainder(23, 5.5))

print (math.remainder(12.5, 2.5))

print (math.remainder(12, 2))

输出结果:


示例

1.0
0.0
2.0
-1.5
1.0
0.0
0.0

Python math 模块

上一节: Ref_math_radians 下一节: Ref_math_sin
此页面最后编辑于2022年8月17日 (星期三) 21:52。