Python abs() function
The abs() function returns the absolute value of a number.
Syntax
1 2 3 |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# 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
1 2 3 4 5 |
Absolute value for integer number: 54.26 Absolute value for float number: 94 Absolute value for complex number: 5.0 |