Python abs() function
Return the absolute value: the distance from zero, always positive.
Syntax
abs(x)
Handy for differences, where only the size matters, not the direction.
Parameters
| x | a number |
Return value
a number of the same type
Example
Code
print(abs(-7), abs(7), abs(-2.5)) predicted, actual = 102.0, 96.5 print("error:", abs(predicted - actual))
Output
7 7 2.5 error: 5.5
Related
Learn it step by step in the free lesson Values, Variables & Numbers, with exercises that check your answers.