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 & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.