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 ... Bootcamp Python Certificate Python Training ... The abs() function returns the absolute value of the specified number....
🌐
Python
docs.python.org › 3 › library › math.html
math — Mathematical functions
2 weeks ago - If x is zero, returns (0.0, 0), otherwise 0.5 <= abs(m) < 1. This is used to “pick apart” the internal representation of a float in a portable way. Note that frexp() 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). math.isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0)¶
🌐
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.
🌐
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.
🌐
Python documentation
docs.python.org › 3 › library › functions.html
Built-in Functions — Python 3.14.3 documentation
2 weeks ago - Return the absolute value of a number. The argument may be an integer, a floating-point number, or an object implementing __abs__().
Find elsewhere
🌐
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) ...
🌐
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....
🌐
Note.nkmk.me
note.nkmk.me › home › python
Get Absolute Values in Python: abs(), math.fabs() - nkmk note
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.
🌐
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.
🌐
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 ...
🌐
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 - There is an alternative method for finding an absolute method in Python: the fabs() method from the math module. This method is designed to offer more precision when working with floats, though it can also accept integers as inputs.
🌐
Profound Academy
profound.academy › python-introduction › min-max-abs-DZ25fuVqi5ass7kZdK1v
min max abs - Introduction to Python
November 1, 2024 - When dealing with computations, ... python provides built-in functions min(), max(), and abs() to compute the minimum, maximum, and the absolute value correspondingly....
🌐
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. It’s a built-in function that accepts integers, floating-point numbers, ...
🌐
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 - It returns the value given as input without the sign with it, that is, the positive value. abs() is a mathematical function. The function abs() is just short for absolute, which returns the absolute value of the input passed in it.
🌐
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.
🌐
FavTutor
favtutor.com › blogs › absolute-value-python
Calculate Absolute Value in Python Using abs() Function - FavTutor
April 30, 2022 - Learn how to calculate python absolute value using abs() and math.fabs() functions along with examples and output.