# abs function in python

In this tutorial we are exploring the abs function in python with example program. ## Python Functions: abs function in Python

In this tutorial we will learn the abs() function of the Python programming language. The abs() function is an in-built function in the Python programming language and you don?t have to install any package to use this function. In this tutorial we will show you the example of using this function in your Python code. So, let?s see the details and use of the abs() function in Python.

Python abs() Function

The abs() function in Python is an in-built function that returns the absolute value of the given number. This function takes only one argument and returns the absolute value of the given number. The abs() function takes integer, float and complex numbers. It returns the absolute numbers in case of integer and float, while this function returns magnitude in case of complex numbers.
So, abs() function is a very useful function when it comes to find the absolute number in case of programming. Now we will see the signature of this function.

Signature

Signature of this function is:

• abs (num)

Parameters

This function takes on parameter: num, which is a number whose absolute value is to be calculated. The abs() function returns the absolute value of the given number.

The abs() function take following parameter type:

• integer
• floating number
• complex number

Return

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

Now we will see the example of usage of the abs() in the Python program.

Python abs() Function Example

Let's see an example to get absolute value of a number.

Here is the code example:

``````
# Exaples of abs function in Python

#absolution value of positive integer
age = 35

print("Absolute value of 35 is: ", abs(age))

# Absolute value of negative integer

negative_integer = -35

print("Absolute value of -35 is: ", abs(negative_integer))

# Absolute value of negative floating data

average_salary = 35020.34

print("Absolute value of float 35020.34 is: ", abs(average_salary))
```
```

Here is the screen shot of the above program execution: In this tutorial we have tried abs() function of Python.

Check more tutorials at: