The abs() method returns the absolute value of a number.
abs() Syntax
abs(number)abs() Parameters
Python abs() function parameters:
| Parameter | Condition | Description |
|---|---|---|
number |
Required | Any number (integer, float or a complex number) |
abs() Return Value
Python abs() method returns:
- For integer numbers, the integer absolute value is returned
- For floating numbers, the floating absolute value is returned
- For complex numbers, the magnitude of the number is returned
Examples
Some examples of how to use abs() function with numbers and complex numbers.
x = -10
print(abs(x))output
10The number may be a floating point number:
x = -12.3
print(abs(x))output
12.3If the number is a complex number, the magnitude of the complex number is returned (i.e. the length of the vector representing the complex number in the complex plane)
x = 3 + 4j
print(abs(x))output
5.0