Javatpoint Logo
Javatpoint Logo

Python abs() Method

Python abs() method is used to get the absolute value of a number. This method takes an argument of an integer or floating type and returns it's absolute value. If the argument is a complex number, it returns its magnitude value. The syntax of the method is given below.

Signature

Parameters

x: An integer, float or a complex number.

Return

It returns absolute value of the number.

Let's see some examples of abs() method to understand it's functionality.

Python abs() Method Example 1

First, let's see a simple example which describes the usage of abs() method. It returns an absolute value of the value.

Output:

Absolute value of -50 is: 50
Absolute value of -50.10 is: 50.1

Python abs() Method Example 2

Any complex value can also be passed to this method to get absolute value. See the example below.

Output:

Absolute value is: 40.11234224026316

Python abs() Method Example 3

Output:

Positive integer absolute value: 20
Negative integer absolute value: 20
Negative float absolute value: 25.5
Complex number absolute value is: 40.11234224026316

Next TopicPython Functions




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA