Contents
Python math.fabs()
math.fabs(x) function returns the absolute value of x.
Syntax
The syntax to call fabs() function is
math.fabs(x)
where
Parameter | Required | Description |
---|---|---|
x | Yes | A numeric value. |
Examples
Absolute value of integer number.
Python Program
import math
x = -8
result = math.fabs(x)
print('fabs(x) :', result)
Run Output
fabs(x) : 8.0
Absolute value of floating point number.
Python Program
import math
x = -8.586
result = math.fabs(x)
print('fabs(x) :', result)
Run Output
fabs(x) : 8.586
Absolute value of negative infinity.
Python Program
import math
x = -math.inf
result = math.fabs(x)
print('fabs(x) :', result)
Run Output
fabs(x) : inf
Summary
In this Python Examples tutorial, we learned the syntax of, and examples for math.fabs() function.