Saturday, March 3, 2018

Number fabs() Method


Number fabs() Method in Python 3:

Description
The fabs() method returns the absolute value of x. Although similar to the abs() function,there are differences between the two functions. They are-

· abs() is a built in function whereas fabs() is defined in math module.
· fabs() function works only on float and integer whereas abs() works with complex number also.

Syntax
Following is the syntax for the fabs() method
Import math
math.fabs( x )

Note: This function is not accessible directly, so we need to import the math module and then we need to call this function using the math static object.

Parameters
x - This is a numeric value.
Return Value
This method returns the absolute value of x.
Example
The following example shows the usage of the fabs() method.



When we run the above program, it produces following result-