fabs()

fabs function returns absolute value of float data type.
Here are some examples with different type of numbers.
import math

print(math.fabs(-4))    # 4.0
print(math.fabs(-4.6))  # 4.6

print(math.fabs(4))     # 4.0
print(math.fabs(4.6))   # 4.6
Data type of the output is float.
import math

print(type(math.fabs(-4)))    # <class 'float'>
print(type(math.fabs(-4.6)))  # <class 'float'>

print(type(math.fabs(4)))     # <class 'float'>
print(type(math.fabs(4.6)))   # <class 'float'>

Complex Number

print(math.fabs(4+8j))
This will generate error message saying TypeError: can't convert complex to float.

Using abs()

We can use built in function abs() to get absolute value of complex number.
print(abs(4+8j))  # 8.94427190999916
print(type(abs(4+8j)))  # <class 'float'>

Difference between fabs() and abs()

fabs() is included in Python math module so we have to import it before using. Where as abs() is part of built in functions of core Python so no need to import any library.

fabs() returns float dtype. Whenever input number can’t be converted to float , fabs() generates error. However abs() returns the same dtype of input number.

abs()
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer