abs()
Anonymous contributor
Published May 10, 2021Updated Oct 13, 2023
Contribute to Docs
The abs()
function returns the absolute value of a numeric argument.
Syntax
abs(n)
Return value is the absolute value of the n
parameter, which is of type int
or float
.
The absolute value of n
will be its distance from zero regardless of its direction (i.e., whether it is positive or negative). Since the absolute value is never negative, a positive value will remain unchanged and a negative value will have its negative sign removed.
Example
In the example below, the absolute values of two variables, positive
and negative
, are returned with the abs()
function:
positive = 10negative = -3.5print(abs(positive))print(abs(negative))
This will produce the following output:
103.5
Codebyte Example
The following example returns the absolute value from each element in the numbers
list:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.