Python math.fabs() Method
Example
Remove the - sign of a given number (return absolute value):
#Import math Library
import math
#Remove - sign of given number
print(math.fabs(-66.43))
print(math.fabs(-7))
Try it Yourself »
Definition and Usage
The math.fabs()
method returns the absolute value of a number.
Absolute denotes a non-negative number. This removes the negative sign of the value if it has any.
Unlike abs(), this method always converts the value to a float value. It will throw an exception if it can't.
Syntax
math.fabs(x)
Parameter Values
Parameter | Description |
---|---|
x | Required. A number. If we try anything else except a number, it returns a TypeError |
Technical Details
Return Value: | A float value, representing an absolute value, i.e a non-negative value of a number |
---|---|
Python Version: | 2.6 |