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
| Name | Type | Description |
|---|---|---|
| number | number 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))