The abs() function in Python returns the absolute value of a number, which is its distance from zero on the number line, regardless of its sign.

  • For integers and floats: It returns the non-negative version of the number.
    Example: abs(-5)5, abs(-3.14)3.14

  • For complex numbers: It returns the magnitude (distance from the origin in the complex plane), calculated as √(real² + imag²).
    Example: abs(3 + 4j)5.0

  • For other numeric types: It works with Fraction, Decimal, and custom classes that define the __abs__() method.

abs() is a built-in function—no import required.
❌ It does not work with non-numeric types like strings or lists—this raises a TypeError.

Common use cases include calculating distances, handling errors, and processing data where only magnitude matters (e.g., in financial analysis or machine learning).

🌐
W3Schools
w3schools.com › python › ref_func_abs.asp
Python abs() Function
Python Examples Python Compiler ... Bootcamp Python Certificate Python Training ... The abs() function returns the absolute value of the specified number....
🌐
Python documentation
docs.python.org › 3 › library › functions.html
Built-in Functions — Python 3.14.3 documentation
2 weeks ago - They are listed here in alphabetical order. ... Return the absolute value of a number. The argument may be an integer, a floating-point number, or an object implementing __abs__().
🌐
Real Python
realpython.com › ref › builtin-functions › abs
abs() | Python’s Built-in Functions – Real Python
The abs() function in Python returns a number’s absolute value, which is its distance from zero on the number line, regardless of its sign.
🌐
GeeksforGeeks
geeksforgeeks.org › python › abs-in-python
abs() in Python - GeeksforGeeks
August 30, 2024 - Hence we will use the abs() method to calculate the exact time, distance, and speed. ... We declared 3 functions to calculate speed, distance, and time. Then passed the positive and negative integer and float point values to them using the Python abs() function.
🌐
Programiz
programiz.com › python-programming › methods › built-in › abs
Python abs()
abs() method returns the absolute value of the given number.
🌐
Trymito
trymito.io › excel-to-python › functions › math › ABS
Excel to Python: ABS Function - A Complete Guide | Mito
The ABS function in Excel takes a single parameters and returns its absolute value. ... Get answers from your data, not syntax errors. Download the Mito AI analyst ... Mito is the easiest way to write Excel formulas in Python.
🌐
Codecademy
codecademy.com › article › python-absolute-value-tutorial
How to Use the abs() Function in Python (With Examples) | Codecademy
Learn to use the `abs()` function in Python to calculate absolute values with integers, floating-point numbers, and complex numbers. Explore its syntax, examples, and uses.
🌐
Server Academy
serveracademy.com › blog › python-absolute-value-abs-tutorial
Python Absolute Value Abs() Tutorial - Server Academy
November 12, 2024 - The absolute value represents the distance of a number from zero on the number line, always as a positive value, and Python makes it simple to work with absolute values through the built-in abs() function and other methods in the math library.
Find elsewhere
🌐
Codecademy
codecademy.com › docs › python:numpy › math methods › .abs()
Python:NumPy | Math Methods | .abs() | Codecademy
June 12, 2025 - Calculates the absolute value of a given number or each element in an array.
🌐
DataCamp
datacamp.com › tutorial › python-absolute-value-a-quick-tutorial
Python Absolute Value: A Quick Tutorial | DataCamp
April 11, 2024 - Discover how to find the magnitude of a number regardless of its sign with abs in Python! The absolute value is a critical mathematical function with numerous applications in programming and data analysis. In this article, we cover how to find the absolute value of real and imaginary numbers ...
🌐
LearnDataSci
learndatasci.com › solutions › python-absolute-value
Python Absolute Value – abs() for real and complex numbers – LearnDataSci
In Python, we use j to represent ... \sqrt{6^2+7^2} \approx 9.22$$ Getting the absolute value of a value in Python is quick and easy to do using the abs() function....
🌐
freeCodeCamp
freecodecamp.org › news › python-absolute-value-python-abs-tutorial
Python Absolute Value – Python abs Tutorial
June 20, 2022 - The abs() built-in Python function returns the absolute value of a number.
🌐
YouTube
youtube.com › shorts › 61ofMgWiulA
abs() function in Python: absolute value! - YouTube
Do you want to see more short tip videos?#shorts
Published   December 9, 2024
🌐
YouTube
youtube.com › watch
How to use abs function in Python | Python functions made easy - YouTube
In this beginner's Python tutorial, you will learn how to get the absolute value of an integer in Python. To do so, you will learn how to use the abs() funct...
Published   July 9, 2020
🌐
ThePythonGuru
thepythonguru.com › python-builtin-functions › abs › index.html
Python abs() function - ThePythonGuru.com
The abs() function returns the absolute value (just magnitude without sign) of the number.Its syntax is as follows:abs(x) -> absolute value Par…
🌐
Python
docs.python.org › 3 › library › math.html
math — Mathematical functions
3 weeks ago - Note that modf() has a different call/return pattern than its C equivalents: it takes a single argument and return a pair of values, rather than returning its second return value through an ‘output parameter’ (there is no such thing in Python). ... Return the IEEE 754-style remainder of x with respect to y. For finite x and finite nonzero y, this is the difference x - n*y, where n is the closest integer to the exact value of the quotient x / y. If x / y is exactly halfway between two consecutive integers, the nearest even integer is used for n. The remainder r = remainder(x, y) thus always satisfies abs(r) <= 0.5 * abs(y).