abs() method returns the absolute value of a number that you pass as an argument. The argument may be an integer or a floating point number. If the argument is a complex number, its magnitude is returned.
Python abs() Syntax
abs( x )
abs() takes only one parameter as an argument whose absolute value is returned.
Mathematically, absolute value refers to the distance of that number from zero in the number line, irrespective of negative or positive direction. So, the absolute value of both -15 and 15 is equal to 15.
And in case of complex number, the magnitude is returned as we mentioned earlier.
Python abs() Example
>>> # abs() for integer >>> abs(-3) 3 >>> abs(3) 3 >>> # abs() for floating point number >>> abs(-22.22) 22.22 >>> # abs() for complex number >>> abs(3 + 4j) 5