Easy Tutorial
❮ Python Upper Lower Python Func Number Exp ❯

Python3 fabs() Function

Python3 Numbers


Description

The fabs() method returns the absolute value of a number, such as math.fabs(-10) returning 10.0.

The fabs() function is similar to the abs() function, but it has two differences:


Syntax

Here is the syntax for the fabs() method:

import math

math.fabs(x)

Note: The fabs() function cannot be accessed directly; it needs to be imported from the math module and called via a static object.


Parameters


Return Value


Example

The following demonstrates the use of the fabs() method:

#!/usr/bin/python3
import math   # Import the math module

print("math.fabs(-45.17) : ", math.fabs(-45.17))
print("math.fabs(100.12) : ", math.fabs(100.12))
print("math.fabs(100.72) : ", math.fabs(100.72))
print("math.fabs(math.pi) : ", math.fabs(math.pi))

The output of the above example is:

math.fabs(-45.17) :  45.17
math.fabs(100.12) :  100.12
math.fabs(100.72) :  100.72
math.fabs(math.pi) :  3.141592653589793

Python3 Numbers

❮ Python Upper Lower Python Func Number Exp ❯