abs()

Takes in a numeric data type such as int or float and returns the absolute value of the argument.

Syntax

abs(n)

Example 1

Use abs() to return the absolute value of -6.5:

print(abs(-6.5))
# Output: 6.5

Example 2

Use abs() to return the absolute value of the numbers list:

Edit this page on GitHub

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your feedback.

Learn Python on Codecademy

Edit this page on GitHub

Contributors