Google News
logo
Python Program to Return the absolute value of a number
In the following example of Python Program to Return the absolute value of a number :
Program :
num = -4.5
abs_num = abs(num)
print(f"The absolute value of {num} is {abs_num}")
Output :
The absolute value of -4.5 is 4.5
In the above program, we use the built-in `abs()` function to calculate the absolute value of the variable `num`.

The absolute value of a number is always a positive value, so `abs_num` will be `4.5` in this case. We then use an f-string to print out the original number and its absolute value.