带有Python示例的math.remainder()方法

Python math.remainder() 方法

math.remainder()方法数学模块的库方法,用于查找给定数字的余数,它接受两个数字(整数或浮点数),并针对浮点数中的第二个数字返回第一个数字的余数。

注意: math.remainder()的新版本的Python中提供了该方法Python 3.7

它的语法 math.remainder() 方法:

    math.remainder(a, b)

Parameter(s): a,b –需要计算其余数的数字。

返回值: float-它返回一个浮点值,该值是a相对于b的余数。

示例

    Input:
    a = 10
    b = 7

    # 函数调用
    print(math.remainder(a, b))

    Output:
    3.0

Python代码演示示例 math.remainder() 方法

# python代码演示示例 
# math.remainder() method

# 导入数学模块
import math

# 数字
a = 10
b = 7
# 寻找余数
print(math.remainder(a,b))

a = 10.2
b = 7.1
# 寻找余数
print(math.remainder(a,b))

输出结果

3.0
3.0999999999999996