Easy Tutorial
❮ Python Uwsgi Python Os Walk ❯

Python math.fabs() Method

Python math Module

The math.fabs(x) method in Python returns the absolute value of x.

The absolute value is non-negative, and any negative sign is removed.

Unlike Python's built-in abs() function, this method always converts the value to a float.

Syntax

The syntax for the math.fabs() method is as follows:

math.fabs(x)

Parameter:

Return Value

Returns a float representing the absolute value of x.

Example

The following example returns the absolute value of a number:

Example

# Import math package
import math

# Print absolute values
print(math.fabs(2.77))
print(math.fabs(8.32))
print(math.fabs(-99.29))

Output:

2.77
8.32
99.29

Python math Module

❮ Python Uwsgi Python Os Walk ❯