Menu Close

Python abs() function

In this tutorial, we are going to learn all about the Python abs function to find the absolute value of a number.
In the previous python tutorial, we have covered lots of Python topics, for example, Python string, list, dictionary, and their methods.

What is the Python abs function?

Python abs function is a Python is a built-in function. The abs() function returns the absolute value of the specified number.

Syntax

The syntax of Python abs function is:-

abs(n)

Parameter

abs function in Python accepts one parameter:-

  • n:- Required Number

Return Value

abs() function in Python return the absolute value of a given number.

  • For integer:- An integer’s absolute value is returned.
  • For Floating:- Floating absolute value is returned.
  • For complex:- Magnitude of the complex is returned.

Python abs() example

Here we will see, how to use abs function in Python to getting absolute value of specified number.

Example 1:

Use abs function in python with integer number.

x = abs(120)
print(x)

Output will be:- 120

Example 2:

Use abs function in python with floating number.

y = abs(12.34)
print(y)

Output will be:- 12

Example 3:

Use abs function in python with complex number.

y = abs(12 + 6j)
print(y)

Conclusion

In this tutorial, you have learned all about the abs function to getting the absolute value of a number. If you like this article, please keep visiting for further interesting python tutorials.

For more information:- Click Here

Python all() function

Related Posts