Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python math.fabs() Method

Python math.fabs() Method

Python math Module Python math Module

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

An absolute value is non-negative; a negative sign is removed.

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

Syntax

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

math.fabs(x)

Parameter Description:

Return Value

Returns a floating-point number representing the absolute value of x.

Example

The following example returns the absolute value of numbers:

Example

Import the math package

import

math

Output the absolute values

print

(

math

.

fabs

(

2.77

)

)

print

(

math

.

fabs

(

8.32

)

)

print

(

math

.

fabs

(

99.29

)

)

Output result:



2.77

8.32

99.29

Python math Module Python math Module