Python

abs() Method in Python1 min read

Python number method abs() returns absolute value of x – the (positive) distance between x and zero.

If the number is a complex number, abs() returns its magnitude.




The syntax of abs() method is:

Parameters

The abs() method takes a single argument:

x – number whose absolute value is to be returned. The number can be:

    1. integer
    2. floating number
    3. complex number

Return Value

This method returns absolute value of x.

Example 1

The following example shows the usage of abs() method.

Output:

 

Example 2

The following example shows the usage of abs() method that get magnitude of a complex number

Output:

Leave a Comment