The are a couple of things wrong with your code:

  1. You have a return statement in every branch of your code. That means that you will return from the first iteration of the loop no matter what.
  2. list.append modifies the target instance in place. As is conventional in Python for such methods, it returns None, which, combined with #1 means that you always get a return value of None.

There's also something very strange about your code. You flip the sign of a positive number by multiplying by -1. That makes sense. But then you take the absolute value of a negative number. Why? Flipping the sign is the same as multiplying by -1 for negative numbers too. And even for zero.

In fact, you don't even need to multiply by -1. There's already a "flip the sign" operator: unary -.

You can write your function as a single list comprehension:

def reverse_sign_of_nos_in_a_list(list1):
    return [-x for x in list1]
Answer from Mad Physicist on Stack Overflow
๐ŸŒ
w3resource
w3resource.com โ€บ python-exercises โ€บ challenges โ€บ 1 โ€บ python-challenges-1-exercise-18.php
Python: Reverse the digits of an integer - w3resource
Python Code: def reverse_integer(x): ... ยท Flowchart: Sample Solution-2: Reverses a number: Use str() to convert the number to a string, slice notation to reverse it and str.replace() to remove the sign....
๐ŸŒ
Javatpoint
javatpoint.com โ€บ how-to-reverse-a-number-in-python
How to reverse a number in Python - Javatpoint
How to reverse a number in Python with python, tutorial, tkinter, button, overview, entry, checkbutton, canvas, frame, environment set-up, first python program, basics, data types, operators, etc.
Discussions

python - Reverse sign function returns none - Stack Overflow
I would like to create a function where one passes a list of numbers and gets back another list where the signs of all numbers are reversed. This is my code: def reverse_sign_of_nos_in_a_list(list... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to reverse an int in python? - Stack Overflow
I'm creating a python script which prints out the whole song of '99 bottles of beer', but reversed. The only thing I cannot reverse is the numbers, being integers, not strings. This is my full scr... More on stackoverflow.com
๐ŸŒ stackoverflow.com
if statement - Reverse number in Python - Stack Overflow
I have a homework to make a program that can reverse an input number, but have a requirement to return a sentence with no error when the input is not a number (i.e. words or sentence). For example,... More on stackoverflow.com
๐ŸŒ stackoverflow.com
slice - Reversing a negative number in Python - Stack Overflow
Using slice method in Python we are able to reverse strings and numbers easily. However, how could it be done when the number is negative? def reverse(x): string = str(x) return int(string... More on stackoverflow.com
๐ŸŒ stackoverflow.com
August 11, 2018
๐ŸŒ
PYnative
pynative.com โ€บ home โ€บ python โ€บ programs and examples โ€บ python programs to reverse an integer number
Python Reverse a Number [4 Ways] โ€“ PYnative
March 31, 2025 - num = 123456 sign = -1 if num < ... Integer:', reverse_int) # Output: # Reversed Integer: 654321Code language: Python (python) Run ... If num < 0, sign = -1 (negative number)....
๐ŸŒ
Medium
medium.com โ€บ @ArunaKale โ€บ python-program-to-reverse-a-number-traditional-and-list-methods-explained-step-by-step-478de7b8e0db
How to Reverse a Number in Python: 4 Easy Methods (with Code Examples for Beginners) | by Aruna | Medium
December 17, 2025 - Note: Understanding rev = 0, sign = -1 if num < 0 else 1, and num = abs(num) Before the reversal process begins, the program prepares three important values. At this point, the input number is already validated, and in this example, num is -19.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ reverse a number in python
Reverse a Number in Python - Scaler Topics
June 21, 2024 - In this way, the new string so ... Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching โ‚น23L. ... We use the python reversed() function to reverse a number by this method....
Top answer
1 of 7
4

The are a couple of things wrong with your code:

  1. You have a return statement in every branch of your code. That means that you will return from the first iteration of the loop no matter what.
  2. list.append modifies the target instance in place. As is conventional in Python for such methods, it returns None, which, combined with #1 means that you always get a return value of None.

There's also something very strange about your code. You flip the sign of a positive number by multiplying by -1. That makes sense. But then you take the absolute value of a negative number. Why? Flipping the sign is the same as multiplying by -1 for negative numbers too. And even for zero.

In fact, you don't even need to multiply by -1. There's already a "flip the sign" operator: unary -.

You can write your function as a single list comprehension:

def reverse_sign_of_nos_in_a_list(list1):
    return [-x for x in list1]
2 of 7
1

list.append() method will append the new element in-place and then will return None. So your function returns that None. Also it will return immediatelly after first element of the original list is processed.

def reverse_sign_of_nos_in_a_list(list1):
    """ This function reverses sign of numbers
        in a list and returns a list.
    """
    list2 = []
    for num in list1:
        if num > 0:
            list2.append(num * -1)
        elif num < 0:
            list2.append(abs(num))
        else:
            list2.append(num)
    return list2

print(reverse_sign_of_nos_in_a_list([1,2,3,-1,-2,-3,0]))

Please, note I keep the code as close as possible to the original code. I would implement the function differently.

๐ŸŒ
NxtWave
ccbp.in โ€บ blog โ€บ articles โ€บ reverse-a-number-in-python
Reverse a Number in Python: Methods & Best Practices
We may simply flip the numbers and attach the negative sign to the very end of the new string if that is the case. This would imply that the result would appropriately handle the negative value. There are also a few things to check if you are not getting the result you expect from your code. One example would be you are seeing leading zeros in your reversed number. This can often cause problems. If you reverse 1200 for example, python may give you the result of 0021.
Find elsewhere
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ reverse-integer-in-python
How to reverse a number in Python?
August 1, 2020 - def reverse(num): st=str(num) revst=st[::-1] ans=int(revst) return ans num=12345 print(reverse(num)) ... This method requires mathematical logic. This method can be used when there is a restriction of not converting the number into string.
๐ŸŒ
Code and Debug
codeanddebug.in โ€บ home โ€บ data structures & algorithms โ€บ leetcode #7 : reverse integer python program explained
Leetcode #7 : Reverse Integer Python Program Explained
July 7, 2025 - Intuition: To reverse the digits of an integer, we can repeatedly extract the last digit and build the reversed number step by step. If the original number is negative, we handle the sign separately. ... class Solution: def reverse(self, x: int) -> int: is_negative = False if x < 0: is_negative = True num = abs(x) answer = 0 while num > 0: last_digit = num % 10 answer = (answer * 10) + last_digit num //= 10 if answer < (-(21**31)) or answer > (2**31 - 1): return 0 return -answer if is_negative else answer
๐ŸŒ
GitHub
gist.github.com โ€บ hossainlab โ€บ b58bd9b22dfeb5eeedba4ee37c007946
Python Program To Reverse a Given Number - Gist - GitHub
n = int(input("Enter a number: ")) reversed_number = 0 while(n>0): last_digit = n reversed_number = reversed_number*10+last_digit n = n//10 print("The reversed number is: ",reversed_number) Take input from user and store in a variable called ...
๐ŸŒ
Upgrad
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ reverse a number in python
How to Reverse a Number in Python: 5 Smart Ways with Code
November 11, 2024 - Python automatically removes leading zeros in integers. For example, reversing 120 will give 21 instead of 021. Yes, you can handle negative numbers by first converting the number to a string, excluding the negative sign, reversing the digits, and reapplying the negative sign to the result.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ examples โ€บ reverse-a-number
Python Program to Reverse a Number
To understand this example, you should have the knowledge of the following Python programming topics: ... num = 1234 reversed_num = 0 while num != 0: digit = num % 10 reversed_num = reversed_num * 10 + digit num //= 10 print("Reversed Number: " + str(reversed_num)) ... First, the remainder ...
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-reverse-a-given-number-in-python
How to reverse a given number in Python
Lines 18โ€“19: After the reversal process, if the original number was negative (indicated by the is_negative flag), we apply a negative sign to the reversed_number to maintain the sign consistency. Lines 21โ€“22: Finally, we print both the original number (original_number) and the reversed number (reversed_number). Now that we understand how to reverse a number using a while loop, letโ€™s explore Pythonโ€™s string slicing capabilities to provide a more straightforward approach to reversing a number.
๐ŸŒ
Upgrad
upgrad.com โ€บ home โ€บ blog โ€บ data science โ€บ learn the techniques: how to reverse a number in python efficiently
Learn How to Reverse a Number in Python Efficiently
October 10, 2025 - When learning how to reverse a number in Python, keep these points in mind: A number like 12345 reversed becomes 54321. Leading zeros in the reversed number are usually removed (e.g., 120 โ†’ 21). Negative numbers retain their sign (e.g., -123 โ†’ -321).
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-program-to-reverse-a-number
Python Program to Reverse a Number - GeeksforGeeks
November 18, 2025 - This method reverses the number by converting it to a string, slicing it in reverse order and converting it back to an integer. ... This method extracts digits from the end of the number using % 10 and builds the reversed number digit-by-digit.
๐ŸŒ
datagy
datagy.io โ€บ home โ€บ python posts โ€บ python: reverse a number (3 easy ways)
Python: Reverse a Number (3 Easy Ways) โ€ข datagy
December 20, 2022 - We multiply our reversed number by 10 and add our digit ยท Finally, we return the floored result of our number divided by 10 (this essentially removes the number on the right) This process is repeated until our original number is equal to zero ยท Itโ€™s important to note, this approach only works for integers and will not work for floats. In the next section, youโ€™ll learn how to use Python string indexing to reverse a number.
๐ŸŒ
Edureka
edureka.co โ€บ blog โ€บ how-to-reverse-a-number
How to reverse a number in Python | Python Program Explained | Edureka
September 24, 2019 - Sixth iteration From the Second Iteration, the values of both Number and Reverse have been changed as, Number = 1 and Reverse = 65432 Reminder = Number  Reminder = 1  = 1 Reverse = Reverse *10+ Reminder = 65432 * 10 + 1 Reverse = 654320 + 1 = 654321 Number ended: # Python Program to Reverse a Number using Recursion Num = int(input("Please Enter any Number: ")) Result = 0 def Result_Int(Num): global Result if(Num > 0): Reminder = Num  Result = (Result *10) + Reminder Result_Int(Num //10) return Result Result = Result_Int(Num) print("n Reverse of entered number is = %d" %Result)