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 = -10b = 10.23# function callprint(math.fabs(a))print(math.fabs(b))Output:10.010.23Python代碼演示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
總結
以上是生活随笔為你收集整理的math.fabs_带有Python示例的math.fabs()方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在Python中执行while循环
- 下一篇: long类型20位示例_Java Lon