Python Number fabs() Method


Python number method fabs() returns the absolute value of x.


Following is the syntax for fabs() method −

import math

math.fabs( x )

Note − This function is not accessible directly, so we need to import math module and then we need to call this function using math static object.


  • x − This is a numeric value.

Return Value

This method returns absolute value of x.


The following example shows the usage of fabs() method.

import math   # This will import math module

print "math.fabs(-45.17) : ", math.fabs(-45.17)
print "math.fabs(100.12) : ", math.fabs(100.12)
print "math.fabs(100.72) : ", math.fabs(100.72)
print "math.fabs(119L) : ", math.fabs(119L)
print "math.fabs(math.pi) : ", math.fabs(math.pi)

When we run above program, it produces following result −

math.fabs(-45.17) :  45.17
math.fabs(100.12) :  100.12
math.fabs(100.72) :  100.72
math.fabs(119L) :  119.0
math.fabs(math.pi) :  3.14159265359
Kickstart Your Career

Get certified by completing the course

Get Started