Built-in Functions and Types

abs()

Measure distance from zero without retaining a negative sign. For an ordinary real number the result is nonnegative; for a complex value it is the length of the vector formed by its real and imaginary parts. Custom numeric objects can implement __abs__(). Unsupported operands raise TypeError.

Formal Syntax & Structure

python syntaxpython
abs(number, /)

Parameters & Attributes

NameTypeDescription
numbernumber or object supporting __abs__Value to measure; positional only.

Return Value

number or protocol-defined result

An int stays an int, a float stays a float, and a complex input gives a float magnitude; custom implementations determine their result.

Working Example

Example Snippetpython
temperature_change = -7print(abs(temperature_change))print(abs(5+12j))
Python Reference