What does 5 have to do with absolute value?

Following your logic:

def my_abs(value):
    """Returns absolute value without using abs function"""
    if value <= 0:
        return value * -1
    return value * 1

print(my_abs(-3.5))
>> 3.5
print(my_abs(3.5))
>> 3.5

Other, shorter solutions also exist and can be seen in the other answers.

Answer from DeepSpace on Stack Overflow
๐ŸŒ
Python Guides
pythonguides.com โ€บ python-absolute-value
Get Absolute Value in Python Without Using abs() Function
October 1, 2025 - While Pythonโ€™s built-in abs() is the simplest way to get absolute values, itโ€™s always good to know alternative approaches.
Discussions

Absolute Without abs
Read one integer n. Output its absolute value without using abs(). - Solve a Python programming problem on MeetCode. More on meetcode.in
๐ŸŒ meetcode.in
December 14, 2025
Help with absolute value
But it does make it positive, as can be seen here: https://replit.com/@ShiftyByte/DearSilkyResources#main.py What is the exact issue you are having with this code? More on reddit.com
๐ŸŒ r/learnpython
10
6
November 4, 2021
How to find the absolute value of an integer or float in Python, without using libraries, division, square roots, conditions, or inbuilt functions - Stack Overflow
I wanted to know if it was possible to do such a thing in Python 3. Using abs() is of course not allowed. No importing is allowed as well. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Calculating absolute value in Python - Stack Overflow
Find centralized, trusted content ... more about Collectives ... Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... How do I make a program that asks for one floating point number in Python and then calculates the absolute value... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
MeetCode
meetcode.in โ€บ home โ€บ python questions โ€บ absolute without abs
Python Program to Absolute Without abs with Explanation | MeetCode - Programming Solutions Platform
December 14, 2025 - This problem helps you practice core Python fundamentals in a practical way. It builds intuition around absolute, one, abs. Letโ€™s break it down step by step so you can implement it confidently. ... Read one integer n. Output its absolute value without using abs().
๐ŸŒ
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 in Python, as well as common mistakes that can occur.
Find elsewhere
๐ŸŒ
TradingCode
tradingcode.net โ€บ python โ€บ math โ€บ absolute-value
How to get absolute value of numbers in Python? โ€ข TradingCode
In mathematics, the absolute value ... a number without regard to its sign (Wikipedia, 2019). That is, the absolute value is a value that describes how far a number is from zero. For example, the absolute value of -12 is 12. And the absolute value of 33 is simply 33. Our program uses absolute values when we donโ€™t care about the sign, but simply want the value. Python has two ways ...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_func_abs.asp
Python abs() Function
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... The abs() function returns the absolute value of the specified number.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ absolute value of an index in python
r/learnpython on Reddit: Absolute value of an index in python
November 18, 2023 -

Hello,

I am not very familiar with python, my script is referencing an index of a notepad document. For example:

Value = lines[firsttag][9:21]

In this case, it is referencing a number in the notepad document which contains 12 characters. And I need the absolute value of it. Every time I put the โ€œabs()โ€ after the equal sign or even after the [firsttag]. My code errors out. Please advise.

๐ŸŒ
Real Python
realpython.com โ€บ python-absolute-value
How to Find an Absolute Value in Python โ€“ Real Python
June 4, 2025 - But in truth, all of your hand-made implementations of an absolute value pale in comparison to the abs() function thatโ€™s built into the language. Thatโ€™s because abs() is compiled to blazing-fast machine code, while your pure-Python code isnโ€™t. You should always prefer abs() over your custom functions. It runs much more quickly, an advantage that can really add up when you have a lot of data to process. Additionally, itโ€™s much more versatile, as youโ€™re about to find out.
๐ŸŒ
Iq-inc
iq-inc.com โ€บ python-absolute-value
Python Absolute Value โ€“ IQ Inc
May 19, 2021 - The absolute value of a number is the non-negative value of a number without regard to its sign. This is often useful when you care more about the size of a value, you are calculating a delta from zero in either direction, or you are measuring something that is direction agnostic and only care about the magnitude. In Python...
๐ŸŒ
Codecademy
codecademy.com โ€บ article โ€บ python-absolute-value-tutorial
How to Use the abs() Function in Python (With Examples) | Codecademy
Level up in financial analytics by learning Python to process, analyze, and visualize financial data. ... Absolute value is a fundamental concept that measures the distance of a number from zero without considering its sign. This means the absolute value of a number is always non-negative.
Top answer
1 of 3
106

It's likely because there a built-in functions with the same name, abs. The same is true for np.amax, np.amin and np.round_.

The aliases for the NumPy functions abs, min, max and round are only defined in the top-level package.

So np.abs and np.absolute are completely identical. It doesn't matter which one you use.

There are several advantages to the short names: They are shorter and they are known to Python programmers because the names are identical to the built-in Python functions. So end-users have it easier (less to type, less to remember).

But there are reasons to have different names too: NumPy (or more generally 3rd party packages) sometimes need the Python functions abs, min, etc. So inside the package they define functions with a different name so you can still access the Python functions - and just in the top-level of the package you expose the "shortcuts". Note: Different names are not the only available option in that case: One could work around that with the Python module builtins to access the built-in functions if one shadowed a built-in name.

It might also be the case (but that's pure speculation on my part) that they originally only included the long-named functions absolute (and so on) and only added the short aliases later. Being a large and well-used library the NumPy developers don't remove or deprecate stuff lightly. So they may just keep the long names around because it could break old code/scripts if they would remove them.

2 of 3
23

There also is Python's built-in abs(), but really all those functions are doing the same thing. They're even exactly equally fast! (This is not the case for other functions, like max().)

Code to reproduce the plot:

import numpy as np
import perfplot


def np_absolute(x):
    return np.absolute(x)


def np_abs(x):
    return np.abs(x)


def builtin_abs(x):
    return abs(x)


b = perfplot.bench(
    setup=np.random.rand,
    kernels=[np_abs, np_absolute, builtin_abs],
    n_range=[2 ** k for k in range(25)],
    xlabel="len(data)",
)
b.save("out.png")
b.show()
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ How-to-calculate-absolute-value-in-Python
How to calculate absolute value in Python?
May 20, 2025 - The absolute value is concerned with the value or magnitude of a number instead of the sign attached to the number. That means, if a number is a positive value, the function returns the same value; but if the number is a negative value, the negation of this number is returned. Hence, it is even more useful for complex numbers where the calculation of magnitude involves many steps. Following is the syntax for the Python abs() function โˆ’
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ functions.html
Built-in Functions โ€” Python 3.14.3 documentation
3 weeks ago - Return the absolute value of a number. The argument may be an integer, a floating-point number, or an object implementing __abs__().