  abs () in Python

Python Methods and Functions

The abs () function is used to return the absolute value of a number.
Syntax :

abs (number)   number:  Can be integer, a floating point number or a complex number

Abs () takes only one argument, a number whose absolute value should be returned. The argument can be an integer, floating point, or complex number.

• If the argument is an integer or floating point, abs () returns the absolute value as an integer or floating point comma.
• For a complex number, abs () returns only part of the value, which can also be a floating point number.

 # Python code for illustration # abs () inline function    # float float = - 54.26 print ( 'Absolute value of float is:' , abs ( float ))   # Integer int = - 94 print ( 'Absolute value of integer is:' , abs ( int ))    # Complex number complex = ( 3 - 4j ) < / p> print ( 'Absolute value or Magnitude of complex is:' , abs ( complex ))

Output:

Absolute value of float is: 54.26 Absolute value of integer is: 94 Absolute value or Magnitude of complex is: 5.0