Python | math.fabs() function
Last Updated :
20 Feb, 2023
In Python, math module contains a number of mathematical operations, which can be performed with ease using the module. math.fabs() function returns the absolute value of the number.
Syntax: math.fabs(x)
Parameter:
x: This is a numeric expression.
Returns: the absolute value of the number.
Time Complexity: O(1)
Auxiliary Space: O(1)
Code #1:
Python3
import math
x = - 33.7
print ("The fabs of 33.7 is : ", end = "")
print (math.fabs(x))
|
Output:
The fabs of 33.7 is : 33.7
Code #2:
Python3
import math
print ("math.fabs( - 13.1 ) : ", math.fabs( - 13.1 ))
print ("math.fabs( 101.96 ) : ", math.fabs( 101.96 ))
|
Output:
math.fabs(-13.1) : 13.1
math.fabs(101.96) : 101.96
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...