math.fmod
Python math.fmod()方法 (Python math.fmod() method)
math.fmod() method is a library method of math module, it is used to find the modulus or given numbers, where the first parameter is a dividend and the second parameter is divisor. It accepts two arguments and returns modulus in float type.
math.fmod()方法是数学模块的库方法,用于查找模数或给定数字,其中第一个参数是除数,第二个参数是除数。 它接受两个参数并以浮点类型返回模数。
Note: math.fmod() can be used to get the modules/remainder of positive and negative integers, positive and negative floats.
注意: math.fmod()可用于获取正整数和负整数,正浮点数和负浮点数的模块/余数。
Syntax of math.fmod() method:
math.fmod()方法的语法:
math.fmod(a, b)
Parameter(s): a, b – numbers (positive or negative, integer or float).
参数: a,b –数字(正数或负数,整数或浮点数)。
Return value: float – it returns a float value, which is a remainder (modulus) of given numbers a, b.
返回值: float-返回浮点值,它是给定数字a,b的余数(模)。
Example:
例:
Input:
a = -10
b = 3
# function call
print(math.fmod(a,b))
Output:
-1.0
Python代码演示math.fmod()方法的示例 (Python code to demonstrate example of math.fmod() method)
# Python code to demonstrate example of
# fmod() method
# importing math
import math
# integer positive numbers
a = 10
b = 3
# calculating modules
result = math.fmod(a,b)
print("result = ", result)
# integer negative numbers
a = -10
b = 3
result = math.fmod(a,b)
print("result = ", result)
# float positive numbers
a = 10.123
b = 3.12
result = math.fmod(a,b)
print("result = ", result)
# float negative numbers
a = -10.123
b = 3.12
result = math.fmod(a,b)
print("result = ", result)
Output
输出量
result = 1.0
result = -1.0
result = 0.762999999999999
result = -0.762999999999999
翻译自: https://www.includehelp.com/python/math-fmod-method-with-example.aspx
math.fmod