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'>
print(math.fabs(4+8j))
This will generate error message saying TypeError: can't convert complex to float.
print(abs(4+8j)) # 8.94427190999916
print(type(abs(4+8j))) # <class 'float'>
Author
🎥 Join me live on YouTubePassionate 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.