What is difference in abs() and fabs() in Python?

PythonServer Side ProgrammingProgramming

Both functions return the absolute value of a number by ignoring its sign. However, abs() is a built-in function and doesn't need any library / module to be loaded. The fabs() function on the other hand is defined in math module, hence the same must be imported before using.

>>> abs(-45)
45
>>> abs(110.12)
110.12
>>> import math
>>> math.fabs(-45)
45.0
>>> math.fabs(110.12)
110.12
raja
Updated on 02-Mar-2020 10:05:33

Advertisements