Python math.fabs() Method

❮ Math Methods


Example

Return absolute value:

#Import math Library
import math

#Print absolute values from numbers
print(math.fabs(-66.43))
print(math.fabs(-7))
Try it Yourself »

Definition and Usage

The math.fabs() method returns the absolute value of a number, as a float.

Absolute denotes a non-negative number. This removes the negative sign of the value if it has any.

Unlike Python abs(), this method always converts the value to a float value.


Syntax

math.fabs(x)

Parameter Values

Parameter Description
x Required. A number. If we try anything else except a number, it returns a TypeError

Technical Details

Return Value: A float value, representing the absolute value of x
Python Version: 2.6

❮ Math Methods

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.