×

### Python abs() function in Linux

Python abs() is a standard built-in python function, which is used to returns the absolute value of the given number. If the number is complex, the abs() method returns its magnitude.

Here at Ibmi Media, as part of our Scripting Support Services, we regularly help our Customers to perform related Python fuction queries.

In this context, we shall look into abs() function in Python.

#### More about Python abs() function ?

The abs() function returns the absolute value of the given number.

It's syntax is given below:

`abs(num)`

abs() Parameters involves a single argument.

num - a number whose absolute value is to be returned. The number can be:

• integer.
• floating number.
• complex number.

#### Examples of using Python abs() function

1. Lets take a look at the below function:

`number = -20absolute_number = abs(number)print(absolute_number)`

The output will be:

`20`

2. Get absolute value of a number:

`# random integerinteger = -20print('Absolute value of -20 is:', abs(integer))#random floating numberfloating = -30.33print('Absolute value of -30.33 is:', abs(floating))`

The output will be:

`Absolute value of -20 is: 20Absolute value of -30.33 is: 30.33`

3. Get magnitude of a complex number:

`# random complex numbercomplex = (3 - 4j)print('Magnitude of 3 - 4j is:', abs(complex))`

It's output will look like:

`Magnitude of 3 - 4j is: 5.0`

## Conclusion

This article covers how to use Python abs() function. In fact, The Python abs() method calculates the absolute value of a number. The abs() method takes in one parameter: the number whose absolute value you want to calculate.

#### Resources

• #### How to securely back up your Linux Ubuntu Centos and Debian Server

• #### Easy way to convert cPanel SSL Certificate from PEM format to PFX

• #### How to fix SSL error err sslversion or cipher mismatch

• #### Easy fix to SQL error 5023

• #### Fix Cloudflare error 1018

• #### Setup openvas on linux Debian and Ubuntu

• #### Method to upgrade MySQL in VestaCP

• • • 