The problem is with the loop you are using , Trying modifying it this way

def abs1(array):
    for i in range(len(array)):
        if array[i] < 0:
             array[i] = array[i] * (-1)
    print(array)

The reason is the loop you were previously using was just for accesing list elements but not giving you reference to change anything in list I solved it with using indexes on list.

Answer from KnightKnight on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-absolute-value-of-list-elements
Absolute Value of List Elements - GeeksforGeeks
July 12, 2025 - For example, we are having a list li = [-1, 2, -3, 4, -5] we need to convert all the negative values to its absolute values in list so that output should be [1, 2, 3, 4, 5]. List comprehension is used here to apply the abs() function to each ...
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
Get Absolute Values in Python: abs(), math.fabs() | note.nkmk.me
May 11, 2025 - Here's a simple example where abs() always returns 100: class MyClass: def __abs__(self): return 100 mc = MyClass() print(abs(mc)) # 100 ยท source: abs_usage.py ยท To convert all elements in a list to their absolute values, you can use a list comprehension with abs()....
๐ŸŒ
TradingCode
tradingcode.net โ€บ python โ€บ math โ€บ absolute-value
How to get absolute value of numbers in Python? โ€ข TradingCode
Hereโ€™s how that looks: # Some positive and negative values values = [-40, 58, -69, -84, 51, 76, -12, 36] # Loop through the list and replace # each number with its absolute value for index, value in enumerate(values): values[index] = abs(value)
๐ŸŒ
datagy
datagy.io โ€บ home โ€บ python posts โ€บ python absolute value: abs() in python
Python Absolute Value: Abs() in Python โ€ข datagy
December 15, 2022 - Numpy arrays are list-like structures, but they come with a number of different built-in methods than Python lists do. For example, one the numpy functions, np.abs(), takes a numpy array and converts all of its numbers to their absolute value.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_func_abs.asp
Python abs() Function
Remove List Duplicates Reverse ... Interview Q&A Python Bootcamp Python Certificate Python Training ... The abs() function returns the absolute value ......
๐ŸŒ
LearnDataSci
learndatasci.com โ€บ solutions โ€บ python-absolute-value
Python Absolute Value โ€“ abs() for real and complex numbers โ€“ LearnDataSci
As magnitude is just a distance, ... See below for an example of this: real_number_list = [-4.16, -3.12, 11.88, 16.32] for number in real_number_list: absolute_value = abs(number) print(f'Number: {number}, Absolute Value: {absolute_value}')...
Find elsewhere
๐ŸŒ
Real Python
realpython.com โ€บ python-absolute-value
How to Find an Absolute Value in Python โ€“ Real Python
June 4, 2025 - To calculate the absolute value of a list of numbers in Python, you can use a list comprehension or the map() function to apply abs() to each element in the list.
๐ŸŒ
Server Academy
serveracademy.com โ€บ blog โ€บ python-absolute-value-abs-tutorial
Python Absolute Value Abs() Tutorial - Server Academy
November 12, 2024 - For example, the absolute value of -5 is 5, and the absolute value of 5 is also 5. Absolute values are often used in scenarios where only the magnitude of a number matters, such as distance measurements, loss functions in machine learning, and ...
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ built-in โ€บ abs
Python abs()
For integers - the integer absolute value is returned ยท For floating numbers - the floating absolute value is returned
๐ŸŒ
pythontutorials
pythontutorials.net โ€บ blog โ€บ how-to-obtain-the-absolute-value-of-numbers
How to Obtain Absolute Values of Numbers in a List: Step-by-Step Example Guide โ€” pythontutorials.net
Hereโ€™s how to do it using Pythonโ€™s built-in abs() function, which returns the absolute value of a single number. Basic familiarity with Python (variables, lists, and functions).
๐ŸŒ
Iq-inc
iq-inc.com โ€บ python-absolute-value
Python Absolute Value โ€“ IQ Inc
May 19, 2021 - This is a Python built-in function that is always available. abs(0.1) # 0.1 abs(-0.1) # 0.1 abs(-5) # 5 abs(-1e3) # 1000.0 ยท Sometimes though you might need to get the absolute value from every element in a list.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-absolute-value-python-abs-tutorial
Python Absolute Value โ€“ Python abs Tutorial
June 20, 2022 - You add j to the end of a real number, like so: 1j or 4j.So, an example of a complex number in Python is 2 + 4j or 1 + 2j. Now, when it comes to the return value of the abs() function: For integer numbers, the abs() function returns the absolute ...
๐ŸŒ
Finxter
blog.finxter.com โ€บ 5-best-ways-to-convert-a-python-list-to-absolute-values
5 Best Ways to Convert a Python List to Absolute Values โ€“ Be on the Right Side of Change
Looping through each element in a list and applying the abs() function is the most straightforward approach to converting a list to absolute values. This method is simple and easily understandable even for beginners to Python. ... This code snippet initializes an empty list abs_numbers, iterates ...
๐ŸŒ
GeeksforGeeks
origin.geeksforgeeks.org โ€บ python โ€บ python-absolute-value-of-list-elements
Absolute Value of List Elements - GeeksforGeeks
January 29, 2025 - We are given a list containing ... For example, we are having a list li = [-1, 2, -3, 4, -5] we need to convert all the negative values to its absolute values in list so that output should be [1, 2, 3, 4, 5]....
๐ŸŒ
Python Central
pythoncentral.io โ€บ python-absolute-value-a-detailed-guide-with-examples
Python Absolute Value: A Detailed Guide with Examples | Python Central
March 5, 2025 - Here is an example: complex_num = 3 + 4j print(abs(complex_num)) # Output will be 5.0, calculated as square root of (3ยฒ + 4ยฒ)) While the standard practice is to use the Python absolute value function, there are other methods as well that gets ...
๐ŸŒ
Replit
replit.com โ€บ home โ€บ discover โ€บ how to do absolute value in python
How to do absolute value in Python
February 6, 2026 - While the built-in abs() function is your go-to, exploring other methods can deepen your understanding of Python's flexibility and the logic behind the calculation. number = -15 if number < 0: absolute_value = -number else: absolute_value = ...
๐ŸŒ
Seaborn Line Plots
marsja.se โ€บ home โ€บ programming โ€บ python โ€บ how to get absolute value in python with abs() and pandas
How to get Absolute Value in Python with abs() and Pandas
May 26, 2024 - Second, we used Python list comprehension to loop through these numbers and used the abs() function on each separate number. Note it is also possible to import the math module and use the fabs() method to get the absolute value ...
๐ŸŒ
Python Guides
pythonguides.com โ€บ python-absolute-value
Get Absolute Value in Python Without Using abs() Function
October 1, 2025 - Learn how to get the absolute value in Python without using the built-in abs() function. Explore simple methods with practical examples and explanations.