Python abs () Function
Published February 14, 2022The Python abs() function is a built-in Python function that returns the absolute value of a specified integer. It removes the minus sign from any given number. For example, the absolute value of -7 is 7. The number might be a floating-point, integer, or complex number. In this post, we'll look at how the abs() function works.
The Syntax of abs() function
The abs () function has the following syntax
abs(value) |
where value is the float or integer number
Example
In the example below, we are going to find both the absolute value of a float and an integer
# Initialize an integer number integer_number = -7 # In initialize floating number floating_number = -9.12 print('Absolute value of an Integer Number is:', abs(integer_number)) print('Absolute value of a Floating Number is:', abs(floating_number)) |
Output
Upon executing the code above, you will see the following output
![]() |
Article Contributed By :
|
|
|
|
302 Views |