The abs function
The function abs
returns the absolute value of a number, i.e. it turns a negative number into a positive one.
Syntax
abs(number)
Example
Let's derive the modulus of the number -5
:
num = -5
print(abs(num))
Result of code execution:
5
Example
Let's derive the absolute value of the number 10
:
num = 10
print(abs(num))
Result of code execution:
10
Example
Now let's print the absolute value of the floating-point number -2.5
:
num = -2.5
print(abs(num))
Result of code execution:
2.5