Python math.fabs() Method
Python math.fabs(x) The method returns the absolute value of x.
An absolute value is non-negative; a negative sign is removed.
Unlike Python's built-in abs() , this method always converts the value to a floating-point value.
Syntax
The syntax of the math.fabs() method is as follows:
math.fabs(x)
Parameter Description:
- x -- required, a number. If x is not a number, a TypeError is returned.
Return Value
Returns a floating-point number representing the absolute value of x.
Example
The following example returns the absolute value of numbers:
Example
Import the math package
import
math
Output the absolute values
(
math
.
fabs
(
2.77
)
)
(
math
.
fabs
(
8.32
)
)
(
math
.
fabs
(
99.29
)
)
Output result:
2.77
8.32
99.29
Python math Module