abs()
Try it yourself →Gives the absolute (unsigned) value of a number.
Syntax
abs(number)
Description
Makes it positive if negative, leaves it unchanged if positive. Works on integers and floats.
Returns
The absolute value of the number.
Example
print(abs(-7)) print(abs(3.5))
Expected output
7 3.5
When to use?
Measuring the difference between two values without a sign (e.g. |target - actual|).