abs()

christian.dinh2481 total contributions
Published May 10, 2021Updated Oct 31, 2022
Contribute to Docs
The abs()
function returns the absolute value of a numeric argument.
Syntax
abs(n)
The return value will be 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 belwo, 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:
All contributors
- christian.dinh2481 total contributions
- Anonymous contributorAnonymous contributor3077 total contributions
- Anonymous contributorAnonymous contributor194 total contributions
- Henbeast1 total contribution
- christian.dinh
- Anonymous contributor
- Anonymous contributor
- Henbeast
Looking to contribute?
- 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.