math

abs()

Returns the absolute value of a number. For complex numbers, returns the magnitude.

abs(x)

Parameters

Parameter Purpose
x int, float, complex, or object with __abs__
returns Non-negative number; float for complex input (the magnitude)

Examples

abs(-5)

Returns 5

abs(-3.14)

Returns 3.14

abs(3 + 4j)

Returns 5.0 (magnitude)

Gotcha

abs() of a complex returns a float, not a complex — that's the magnitude sqrt(re^2 + im^2).

Related built-ins

← All Python built-ins