Absolute Value abs() in Python

In python, abs() function returns the absolute value of the number. By using abs function you can return absolute value for integer number, float number or complex number.

Basic Syntax

Following is the basic syntax for abs() function in Python:

abs(number)

And the parameters are:

ParameterDescription
numberInteger number, a float number or any complex number.
Absolute value abs() in Python
Absolute value abs() in Python

Return Value

abs() function returns absolute value for the given number.

  • For an integer value, it will return an integer
  • For float value, it will return a float
  • And if complex number it will return the magnitude part which can also be floating point number.

Example

The output for the above program is as given below:

The Absolute value for integer_value is: 10
Absolute value for float_value is: 5.76
Absolute value or magnitude for complex_number is: 5

LEAVE A REPLY

Please enter your comment!
Please enter your name here