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 20, 2025
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
August 19, 2022
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
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 20, 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 ...
🌐
Reddit
reddit.com › r/learnpython › absolute value of an index in python
r/learnpython on Reddit: Absolute value of an index in python
November 24, 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.

🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › python › abs-in-python
abs() in Python - GeeksforGeeks
August 30, 2024 - In this example, we will pass an Integer value as an argument to the abs() function in Python and print its value to see how it works. ... In this example, we will pass a float data into the abs() function and it will return an absolute value.
🌐
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.
🌐
iO Flood
ioflood.com › blog › python-absolute-value
Python Absolute Value | abs() Function and Alternatives
February 6, 2024 - For real numbers, it returns the number without the sign, while for complex numbers, it returns the magnitude. As you delve deeper into Python, you’ll find this function to be a powerful tool in your arsenal, especially when dealing with mathematical computations involving complex numbers. While the abs() function is the most common method for finding the absolute value in Python, it’s not the only one.
🌐
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 −