Skip to main content

Python abs() Function

The abs() method returns the absolute value of a number.

abs() Syntax

abs(number)

abs() Parameters

Python abs() function parameters:

ParameterConditionDescription
numberRequiredAny number (integer, float or a complex number)

abs() Return Value

Python abs() method returns:

  • For integer numbers, the integer absolute value is returned
  • For floating numbers, the floating absolute value is returned
  • For complex numbers, the magnitude of the number is returned

Examples

Some examples of how to use abs() function with numbers and complex numbers.

# Find absolute value of -10
x = -10
print(abs(x))

output

10

The number may be a floating point number:

x = -12.3
print(abs(x))

output

12.3

If the number is a complex number, the magnitude of the complex number is returned (i.e. the length of the vector representing the complex number in the complex plane)

x = 3 + 4j
print(abs(x))

output

5.0