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:

    math.fabs(n)

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.

Example:

    Input:
    a = -10
    b = 10.23

    # function call
    print(math.fabs(a))
    print(math.fabs(b))

    Output:
    10.0
    10.23

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))

Output

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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.