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

code golf - Find the absolute value of a number without built-in functions - Code Golf Stack Exchange
The challenge is to take any real number as input and output or return the absolute value. You may not use any built-in functions other than those dealing with input and output/returning. This is c... More on codegolf.stackexchange.com
🌐 codegolf.stackexchange.com
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
Absolute value without calling the Math.abs() method?

I think you can probably figure this one out just with a hint.

What happens to negative numbers when they are multiplied by -1?

Note that you can check if numbers are less than zero using if and then do something about less than zero numbers.

If you still get stuck after thinking on that for a few minutes shoot me a pm.

Edit: as long as you don't ask me to just write out all the code for you.

More on reddit.com
🌐 r/javahelp
7
1
December 28, 2015
🌐
YouTube
youtube.com › codepoint
how to get absolute value in python without using abs - YouTube
Instantly Download or Run the code at https://codegive.com certainly! in python, the abs() function is commonly used to obtain the absolute value of a numbe...
Published   February 19, 2024
Views   253
🌐
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
🌐
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.
🌐
X
x.com › pythonguides › status › 1881123223372177680
How to get absolute value in Python without using abs - X
January 19, 2025 - We’ve detected that JavaScript is disabled in this browser. Please enable JavaScript or switch to a supported browser to continue using x.com. You can see a list of supported browsers in our Help Center · By signing up, you agree to the Terms of Service and Privacy Policy, including Cookie Use
🌐
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).
🌐
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.
🌐
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. Let’s see it in action: number = -15 absolute_value = abs(number) print(absolute_value) # Output: # 15
Top answer
1 of 2
1
Final Answer: To print the absolute value of a number x in Python without the abs function, use an if statement to check if x is negative. If x is negative, multiply it by -1; otherwise, print x directly. This ensures that the output is always a non-negative number. ; Explanation: To find the absolute value of a number x in Python without using the abs() function, you can use an if statement. This statement checks whether x is less than zero. If it is, the code multiplies x by -1 to convert it to a positive value. If x is not negative (meaning it is zero or positive), it can be printed directly. This method effectively ensures that regardless of the original value of x , the output will always be a non-negative number. Here is how the code works step-by-step: Use an if statement to check if x < 0 . If the condition is true (meaning that x is negative), execute print(-x) to convert it to its positive counterpart. If the condition is false (meaning that x is either positive or zero), execute print(x) to return the number as is. Here's the code that implements this logic: if x < 0: print(-x) else: print(x) You can test this code with different values of x . For example, if x is -5, the output will be 5 . If x is 7, the output will be 7 . This approach neatly avoids using the built-in absolute value function while still achieving the correct result. ; Examples & Evidence: For instance, if you set x to -3, the code will output 3 . For x set to 4, it will output 4 as expected. The logic that negative numbers can be converted to positive by multiplying by -1 is based on fundamental arithmetic principles, ensuring accuracy in computation.
2 of 2
1
This answer is FREE! Final answer: To find the absolute **value **of a number in Python without using the abs() function , you can use an if statement to check if the number is negative or positive. If the number is negative, you can multiply it by -1 to make it positive. Otherwise, if the number is already positive, you can leave it as is. Explanation: To find the absolute value of a number in Python without using the abs() function, you can use an if statement to check if the number is negative or positive . If the number is negative, you can multiply it by -1 to make it positive. Otherwise, if the number is already positive, you can leave it as is. x = -5 if x < 0: absolute_value = x * -1 else: absolute_value = x print('The absolute value of', x, 'is', absolute_value) In this example, assuming x is -5, the program will output: 'The absolute value of -5 is 5'. Learn more about Absolute Value here: https://brainly.com/question/18731489 #SPJ11
🌐
Reddit
reddit.com › r/learnpython › absolute value of an index in python
r/learnpython on Reddit: Absolute value of an index in python
November 26, 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.

🌐
TutorialsPoint
tutorialspoint.com › how-to-calculate-absolute-value-in-python
How to calculate absolute value in Python?
May 20, 2025 - Return the negative of the value if the condition is true i.e -(-) value becomes plus(+) which is the absolute value.