Absolute Value abs() in Python

In python, abs() function returns the absolute value of the number. By using abs function you can return absolute value for integer number, float number or complex number.

Basic Syntax

Following is the basic syntax for abs() function in Python:

abs(number)

And the parameters are:

Parameter Description
number Integer number, a float number or any complex number.
Absolute value abs() in Python
Absolute value abs() in Python

Return Value

abs() function returns absolute value for the given number.

  • For an integer value, it will return an integer
  • For float value, it will return a float
  • And if complex number it will return the magnitude part which can also be floating point number.

Example

# Program for abs() in Python
integer_value = -10
print('The Absolute value for integer_value is: ', abs(integer_value))

float_value = -5.76
print('Absolute value for float_value is: ', abs(float_value))

complex_number = 3-4j;
print('Absolute value or magnitude for complex_number is: ', abs(complex_number))

The output for the above program is as given below:

The Absolute value for integer_value is: 10
Absolute value for float_value is: 5.76
Absolute value or magnitude for complex_number is: 5