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

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

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值