Python abs() function
Python abs() function
The abs() function returns the absolute value of a number.
Syntax
abs(x)
Parameter
x: The parameter ‘x’ can be an integer value, a floating point number or a complex number.
Return
This function returns the absolute value of a number, but if the argument is a complex number, its magnitude is returned.
Example 1
# Python Program explaining
# abs() built-in function
# passing floating point number
float_val = -54.26
print('Absolute value for integer number:', abs(float_val))
# passing An integer number
int_val = -94
print('Absolute value for float number:', abs(int_val))
# passing a complex number
complex_val = (3 - 4j)
print('Absolute value for complex number:', abs(complex_val))
Output
Absolute value for integer number: 54.26 Absolute value for float number: 94 Absolute value for complex number: 5.0
