Python math module - fabs function

The fabs function returns the absolute value of a number. It returns the quantity, magnitude without the direction on the numberline

Math Updated 25 Sep 2016 1 min read

Method Name

fabs(aNumber_in)

Method Overview

Returns the absolute value of a Number.
If we draw a number line the absolute value of a number tells the magnitude of its distance from zero,
without considering the direction. Hence both the numbers -6 and 6 will be at a distance of 6 from zero.

python
import math

# Absolute zero temperature is -273 degree celcius

AbsolouteZero = -273

Magnitude = math.fabs(-273)

print("Printing only the magnitude for absolute zero: {}".format(Magnitude))

# Number of storeys below ground floor in my apartment...0 being ground floor

maxFloorBelow = -2

FloorCountBelowGround = math.fabs(maxFloorBelow)

print("The number of floors below ground: {}".format(FloorCountBelowGround))

Output

Output
Printing only the magnitude for absolute zero: 273.0

The number of floors below ground: 2.0