Python abs() Function

Returns the absolute value of a number

Usage

The abs() method returns the absolute value of a number.

Syntax

abs(number)

Python abs() function parameters
ParameterConditionDescription
numberRequiredAny number (integer, float or a complex number)

Examples

# Find absolute value of -10
x = -10
print(abs(x))
# Prints 10

The number may be a floating point number.

x = -20.5
print(abs(x))
# Prints 20.5

If the number is a complex number, its magnitude is returned.

x = 3 + 4j
print(abs(x))
# Prints 5.0