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: Returns the non-negative value of the number.

    abs(-5)    # Returns 5
    abs(-3.14) # Returns 3.14
  • For complex numbers: Returns the magnitude (modulus), calculated as √(real² + imag²).

    abs(3 + 4j) # Returns 5.0 (since √(3² + 4²) = 5)
  • For other types: The function can be customized in user-defined classes by implementing the __abs__() special method.

This function is commonly used for:

  • Calculating distances between points.

  • Measuring deviations or errors (e.g., in data analysis).

  • Ensuring positive values in mathematical operations.

🌐
W3Schools
w3schools.com › python › ref_func_abs.asp
Python abs() Function
Python Examples Python Compiler ... Q&A Python Bootcamp Python Certificate Python Training ... The abs() function returns the absolute value of the specified number....
🌐
Note.nkmk.me
note.nkmk.me › home › python
Get Absolute Values in Python: abs(), math.fabs() | note.nkmk.me
May 11, 2025 - Passing a complex number (complex) to abs() returns its absolute value (also known as its modulus or magnitude) as a float. print(abs(1 + 1j)) # 1.4142135623730951 print(abs(3 + 4j)) # 5.0 print(type(abs(3 + 4j))) # <class 'float'> ... When abs() is called, it internally invokes the object's special method __abs__(). In other words, abs(x) is equivalent to x.__abs__(). 3. Data model - __abs__(self) — Python 3.13.3 documentation
🌐
Real Python
realpython.com › python-absolute-value
How to Find an Absolute Value in Python – Real Python
June 4, 2025 - Learn how to calculate the Python absolute value with abs(), implement the math behind it from scratch, and customize it in your own classes.
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.absolute.html
numpy.absolute — NumPy v2.1 Manual
numpy.absolute(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature]) = <ufunc 'absolute'>#
🌐
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.
🌐
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.
🌐
Python documentation
docs.python.org › 3 › library › functions.html
Built-in Functions — Python 3.14.3 documentation
3 weeks ago - The Python interpreter has a number of functions and types built into it that are always available. 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__().
🌐
GeeksforGeeks
geeksforgeeks.org › python › abs-in-python
abs() in Python - GeeksforGeeks
August 30, 2024 - The Python abs() function return the absolute value.
🌐
Trymito
trymito.io › excel-to-python › functions › math › ABS
Excel to Python: ABS Function - A Complete Guide | Mito
To replicate the ABS function in Excel using Python and Pandas, you can use the `abs()` function available in Pandas. Below are examples of how to achieve the same functionality. The most common way to use the function in Excel is to apply it directly to a column or series of numbers in a Pandas DataFrame. # Calculate the absolute value of the Numbers column df['ABS_Result'] = df['Numbers'].abs()
Find elsewhere
🌐
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.
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.absolute.html
numpy.absolute — NumPy v2.5.dev0 Manual
numpy.absolute(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature]) = <ufunc 'absolute'>#
🌐
Programiz
programiz.com › python-programming › methods › built-in › abs
Python abs()
abs() method returns the absolute value of the given number.
🌐
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....
🌐
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 ...
🌐
Replit
replit.com › home › discover › how to do absolute value in python
How to do absolute value in Python
February 6, 2026 - While the built-in abs() function is your go-to, exploring other methods can deepen your understanding of Python's flexibility and the logic behind the calculation. number = -15 if number < 0: absolute_value = -number else: absolute_value = number print(absolute_value)--OUTPUT--15
🌐
Vultr Docs
docs.vultr.com › python › built-in › abs
Python abs() - Get Absolute Value | Vultr Docs
September 27, 2024 - The abs() function in Python computes the absolute value of a given number, which is the number's distance from zero on the number line without considering the direction.
🌐
TradingCode
tradingcode.net › python › math › absolute-value
How to get absolute value of numbers in Python? • TradingCode
An absolute value is a number's non-negative value. Python code gets those with the abs() function. This article explains how (including lists & arrays).
🌐
Flexiple
flexiple.com › python › absolute-value-python
Python Absolute Value - Python abs Tutorial - Flexiple
March 11, 2022 - Python's abs() function is a fundamental tool for computing the absolute value of numerical data in Python. It is a built-in function that returns the absolute value of a number, removing any negative sign if present.
🌐
iO Flood
ioflood.com › blog › python-absolute-value
Python Absolute Value | abs() Function and Alternatives
February 6, 2024 - Python’s abs() function is a built-in function used to return the absolute value of a number. The absolute value of a number is its distance from zero, regardless of the direction. In other words, it’s the non-negative value of a number.