Python | math.fabs() function

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.

Code #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python code to demonstrate the working of fabs()
    
# importing "math" for mathematical operations 
import math 
    
x = -33.7
    
# returning the fabs of 33.7
print ("The fabs of 33.7 is : ", end ="") 
print (math.fabs(x))

chevron_right


Output:



The fabs of 33.7 is : 33.7

 
Code #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python code to demonstrate the working of fabs()
    
# importing "math" for mathematical operations 
import math 
    
# prints the fabs using fabs() method 
print ("math.fabs(-13.1) : ", math.fabs(-13.1))
print ("math.fabs(101.96) : ", math.fabs(101.96))

chevron_right


Output:

math.fabs(-13.1) :  13.1
math.fabs(101.96) :  101.96


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.