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

math.fabs

Python math.fabs()方法 (Python math.fabs() method)

math.fabs() method is a library method of math module, it is used to get the absolute value of a number, it accepts a number (that can be either positive integer/float or negative integer/float) and returns an absolute value in the float type.

math.fabs()方法数学模块的库方法,用于获取数字的绝对值,它接受数字(可以为正整数/浮点数或负整数/浮点数)并返回绝对值在浮点类型。

Syntax of math.fabs() method:

math.fabs()方法的语法:

    math.fabs(n)

Parameter(s): n – a number or a numeric expression.

参数: n-数字或数字表达式。

Return value: float – it returns a float value, which is an absolute value of given number/numeric expression n.

返回值: float-返回浮点值,它是给定数字/数字表达式n的绝对值。

Example:

例:

    Input:
    a = -10
    b = 10.23

    # function call
    print(math.fabs(a))
    print(math.fabs(b))

    Output:
    10.0
    10.23

Python代码演示math.fabs()方法的示例 (Python code to demonstrate example of math.fabs() method)

# Python code to demonstrate example of 
# math.fabs() method

# importing math module
import math

# numbers
a = 10      # +ve integer
b = 10.23   # +ve float
c = -10     # -ve integer 
d = -10.23  # -ve float 

# printing absolute values
print("fabs(a): ", math.fabs(a))
print("fabs(b): ", math.fabs(b))
print("fabs(c): ", math.fabs(c))
print("fabs(d): ", math.fabs(d))

Output

输出量

fabs(a):  10.0
fabs(b):  10.23
fabs(c):  10.0
fabs(d):  10.23


翻译自: https://www.includehelp.com/python/math-fabs-method-with-example.aspx

math.fabs

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值