Python Tutorial Python Advanced Python References Python Libraries

Python math - fabs() Function



The Python math.fabs() function returns the absolute value (positive value) of the specified number.

Syntax

math.fabs(arg)

Parameters

arg Required. Specify a number whose absolute value need to be determined.

Return Value

Returns the absolute value (positive value) of the argument.

Example:

In the example below, fabs() function returns the absolute value (positive value) of the specified number.

import math

print(math.fabs(10))
print(math.fabs(-10))
print(math.fabs(-5.5))
print(math.fabs(-10.5))

The output of the above code will be:

10.0
10.0
5.5
10.5

❮ Python Math Module