abs() is a built-in function, so just replace all occurrences of math.abs with abs.

You should also use the isinstance() function for type checking instead of using type() and comparing, for example:

def distance_from_zero(num):
    if isinstance(num, (int, float)):
        return abs(num)
    else:
        return "Not an integer or float!"

Note that you may also want to include long and complex as valid numeric types.

Answer from Andrew Clark on Stack Overflow
🌐
W3Schools
w3schools.com › python › ref_func_abs.asp
Python abs() Function
Built-in Modules Random Module ... Q&A Python Bootcamp Python Certificate Python Training ... The abs() function returns the absolute value of the specified number....
🌐
GeeksforGeeks
geeksforgeeks.org › python › abs-in-python
abs() in Python - GeeksforGeeks
August 30, 2024 - The Python abs() function return the absolute value. The absolute value of any number is always positive it removes the negative sign of a number in Python.
🌐
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.
🌐
Server Academy
serveracademy.com › blog › python-absolute-value-abs-tutorial
Python Absolute Value Abs() Tutorial - Server Academy
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.
🌐
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....
🌐
Programiz
programiz.com › python-programming › methods › built-in › abs
Python abs()
Python Mathematical Functions · Python Random Module · Python Programming Built-in Functions · Python int() The abs() function returns the absolute value of the given number. If the number is a complex number, abs() returns its magnitude. number = -20 · absolute_number = abs(number) ...
🌐
DataCamp
datacamp.com › tutorial › python-absolute-value-a-quick-tutorial
Python Absolute Value: A Quick Tutorial | DataCamp
April 11, 2024 - Key Takeaway: To use the abs() function, simply provide the number as an argument, and it will return its absolute value. For greater precision with floats, use the math.fabs() function. There are many situations where a negative number doesn’t make sense or would cause problems.
Find elsewhere
🌐
Codecademy
codecademy.com › docs › python:numpy › math methods › .abs()
Python:NumPy | Math Methods | .abs() | Codecademy
June 12, 2025 - It applies the absolute value operation element-wise across all dimensions, preserving the original array shape. The function returns positive infinity for both positive and negative infinity inputs.
🌐
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.
🌐
Tutorialspoint
tutorialspoint.com › python › number_abs.htm
Python abs() function
The Python abs() function returns the absolute value of a number. In simple words, an absolute value of a number 'x' is calculated as the (positive) distance between x and 0. The abs() function accepts all types of numbers, both real and complex
🌐
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. But what is an absolute value of a number in the first place? In mathematics, the absolute value of a number refers to that number's distance from zero.
🌐
Scaler
scaler.com › home › topics › python abs() function
Python abs() Function - Scaler topics
December 4, 2023 - The standard Python library has a function abs(), short for "absolute" value. It returns the value given as input without the sign with it, that is, the positive value. abs() is a mathematical function.
🌐
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.
🌐
Note.nkmk.me
note.nkmk.me › home › python
Get Absolute Values in Python: abs(), math.fabs() | note.nkmk.me
May 11, 2025 - In Python, you can get the absolute value of a number using either the built-in abs() function or the math module's fabs() function.
🌐
Trymito
trymito.io › excel-to-python › functions › math › ABS
Excel to Python: ABS Function - A Complete Guide | Mito
Math · ABS · Related FunctionsSUMROUNDCEIL · Excel's ABS function finds the absolute value of a number. The absolute value of a function is the non-negative value of a number. The absolute value function is commonly used, for example, to ...
🌐
TradingCode
tradingcode.net › python › math › absolute-value
How to get absolute value of numbers in Python? • TradingCode
Python’s abs() function returns the absolute value for integer and floating-point numbers. To use it, we call the function and provide it with an argument that we want the absolute value of.
🌐
GitHub
github.com › TheAlgorithms › Python › blob › master › maths › abs.py
Python/maths/abs.py at master · TheAlgorithms/Python
def abs_min(x: list[int]) -> int: """ >>> abs_min([0,5,1,11]) 0 · >>> abs_min([3,-10,-2]) -2 · >>> abs_min([]) Traceback (most recent call last): ... ValueError: abs_min() arg is an empty sequence · """ if len(x) == 0: raise ValueError("abs_min() arg is an empty sequence") j = x[0] for i in x: if abs_val(i) < abs_val(j): j = i ·
Author   TheAlgorithms