Home >>Python math Module >Python math.fabs() Method

Python math.fabs() Method

Python math.fabs() Method

Python math.fabs() method in python returns an absolute value of a number in the float type and it accepts a number (either positive/ negative integer).

Syntax:
math.fabs(x)

Parameter Values

Parameter Description
x It is required a number to return the absolute value
Here is an example of Python math.fabs() Method:

import math  
print(math.fabs(-21.34))
print(math.fabs(-2))

Output:
21.34
2.0
Example 2:

import math
w = -23      
x = 45   
y = -15      
z = 35   
print("fabs(w): ", math.fabs(w))
print("fabs(x): ", math.fabs(x))
print("fabs(y): ", math.fabs(y))
print("fabs(z): ", math.fabs(z))

Output:
fabs(w): 23.0
fabs(x): 45.0
fabs(y): 15.0
fabs(z): 35.0