Python abs() function

abs() is a built-in function in Python programming language which gives a positive value of any number in return. It means it converts any negative number into a positive number and positive numbers remain unchanged. If a given argument is a complex number then the abs() function returns its magnitude as a floating point number of a given complex number.

abs() function is a part of Python Built-in Functions.

abs() Syntax

abs( n )


abs() Parameters

n – where n is any number or numeric expression in Python i-e integer, float or complex.


abs() Return Value

abs() function returns an positive/absolute value of a given number. The return value depends on input parameter.

  • If an input parameter is an integer then return value is an integer.
  • If an input parameter is a float or a complex then abs function returns type is a floating point number.


abs() Compatibility

This function is available and compatible with both Python 2.x and 3.x

Python 2.xPython 3.x


abs() Function Examples


An integer in abs()

an integer is a simple number like 2, -23, 100, -99999 etc.


Return value: 23


A floating point number in abs()

floating point is a number with a decimal point like 43.92, -444.93, -12.98 etc.


Return value: 12.98


A complex number in abs()

A complex number is a number that can be expressed in the form of (a + bj), where a and b are real numbers and j is the imaginary unit. In complex numbers, abs() function returns floating representation of the complex number. some of the examples of a complex number are (-25+2j), (6-500j).



25.079872407968907 and 500.0359987040933 respectively.