In Python 3, what built-in function returns the absolute value of a number?

The story behind the answer

In Python 3, the built-in function `abs()` returns the absolute value of a number.

For integers and floating-point values, `abs()` removes the sign from a negative value: `abs(-7)` produces `7`, while `abs(3.5)` produces `3.5`. It also accepts complex numbers, returning their magnitude, and supports custom objects that define the special method `__abs__()`.

`abs()` is available automatically, so no import is needed. A common mix-up is `math.fabs()`, which is a separate function from the `math` module and returns a floating-point result. `fabs()` is not the standard built-in answer, while `mod()` and `absolute()` are not Python built-in functions for this purpose.

The concept comes from mathematics: a number’s absolute value represents its distance from zero on the number line. Python applies that idea directly through a short, readable function name. For complex values such as `3+4j`, `abs()` returns `5.0`, the Euclidean magnitude.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: