Home » Python

math.fabs() method with example in Python

Python math.fabs() method: Here, we are going to learn about the math.fabs() method with example in Python.
Submitted by IncludeHelp, on April 17, 2019

Python math.fabs() method

math.fabs() method is a library method of math module, it is used to get the absolute value of a number, it accepts a number (that can be either positive integer/float or negative integer/float) and returns an absolute value in the float type.

Syntax of math.fabs() method:


Parameter(s): n – a number or a numeric expression.

Return value: float – it returns a float value, which is an absolute value of given number/numeric expression n.


    a = -10
    b = 10.23

    # function call


Python code to demonstrate example of math.fabs() method

# Python code to demonstrate example of 
# math.fabs() method

# importing math module
import math

# numbers
a = 10      # +ve integer
b = 10.23   # +ve float
c = -10     # -ve integer 
d = -10.23  # -ve float 

# printing absolute values
print("fabs(a): ", math.fabs(a))
print("fabs(b): ", math.fabs(b))
print("fabs(c): ", math.fabs(c))
print("fabs(d): ", math.fabs(d))


fabs(a):  10.0
fabs(b):  10.23
fabs(c):  10.0
fabs(d):  10.23

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.