How to Find Absolute Value in Python using fabs() Function

The absolute value of an integer in Python Programming Language can be found by using a fabs() function from Python Standard math Library.

math.fabs() function in Python

fabs() function exists in Standard math Library of Python Programming Language. The purpose of this function is to return an absolute (positive) value of any numeric expression.


Python math.fabs() Function Syntax

The syntax of math.fabs() function in Python is:
math.fabs( x )


Python fabs() Function Parameters

x – Any valid Python positive or negative number. This parameter is required.
Note: if the x parameter is not a number, fabs() function will return an error.


Python fabs() Function Compatibility

Python 2.x – Yes
Python 3.x – Yes


Python fabs() Function Return Value

This function will return an absolute or positive value.


Python fabs() Function Examples

# import math library
import math

Output of Python fabs() Function:


Note that in output all the numbers whether they are negative or positive are converted into a positive number by using fabs() function.