The abs() function in Python prints out the absolute value of a number which means it will delete the negative sign of that number.
abs() only applies to one argument such as an integer, a rational number, or complex number. This is a very useful tool in math and should be included in schools.
And we will show you how to use the abs() function in Python as you go through it below. Hope you understand.
x = abs(-80) print(x)
The abs() function prints out the absolute value of the specified argument.
The abs() function turns any negative number into a positive number and the positive numbers are not changed.
The absolute value of a number is always positive.
number: a number (required)
Example 1: The problem of calculating the difference of 2 numbers and printing the absolute value of the result
print("Enter the 1st number:") x = int(input()) print("Enter the 2nd number:") y = int(input()) z = x - y print("Result:", z) print("Absolute:", abs(z))
Enter the 1st number: 6
Enter the 2nd number: 9
Example 2: With complex numbers
x = abs(3+4j) print(x)
Hope you understood the tutorial on how to use the abs() function in Python.
Thanks for reading!