Python abs() Function

abs() is a Python built-in function to return the absolute value of a number.

Example 1 - abs() with negative interger number argument

x = abs(-5)
print(x)
Output:

5

Example 2 - abs() with positive interger number argument

x = abs(5)
print(x)
Output:

5

Example 3 - abs() with 0 in argument

x = abs(0)
print(x)
Output:

0

Example 4 - abs() with negative float number argument

x = abs(-9.5)
print(x)
Output:

9.5

Example 5 - abs() with positive float number argument

x = abs(9.5)
print(x)
Output:

9.5
Tags: