Without converting the number to a string:

def reverse_number(n):
    r = 0
    while n > 0:
        r *= 10
        r += n % 10
        n /= 10
    return r

print(reverse_number(123))
Answer from Alberto on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-program-to-reverse-a-number
Python Program to Reverse a Number - GeeksforGeeks
November 18, 2025 - Recursion works by repeatedly removing the last digit from the number and building the reversed number during the returning phase.
🌐
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))
Discussions

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
Can anyone explain how to reverse a integer number?
That's hardly cheating, and is now I'd do it unless that method was explicitly forbidden (I had that once). Your div/mod way is more complicated, and in my experience, likely doesn't have much in the way of noticeable performance advantages anyway. Abusing strings is often a good solution surprisingly (but consider each case individually). More on reddit.com
🌐 r/learnpython
26
38
February 1, 2022
Why does [::1] reverse a string in Python?
On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge. If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options: Limiting your involvement with Reddit, or Temporarily refraining from using Reddit Cancelling your subscription of Reddit Premium as a way to voice your protest. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/learnprogramming
15
12
September 21, 2023
Need help with reversing a binary number as a second function
bin(6)[2:][::-1] def binary(num): return int(bin(number)[2:]) def reverse_num(num): string_num = str(num) return int(string_num[::-1]) More on reddit.com
🌐 r/learnpython
17
1
June 23, 2021
People also ask

What are the benefits of using recursion to reverse a number in Python?
Recursion simplifies the process by repeatedly calling the function to break down the number and reverse it until it’s done.
🌐
wscubetech.com
wscubetech.com › resources › python › programs › reverse-number
Reverse a Number in Python (5 Different Ways)
Can I reverse a number using loops in Python?
Yes, you can reverse a number by using a while loop. Divide the number by 10 to extract digits and multiply the result by 10 to rebuild the reversed number step by step.
🌐
wscubetech.com
wscubetech.com › resources › python › programs › reverse-number
Reverse a Number in Python (5 Different Ways)
How can I reverse a number in Python using a string?
You can convert the number to a string with str(), reverse it using slicing ([::-1]), and then turn it back into an integer using int().
🌐
wscubetech.com
wscubetech.com › resources › python › programs › reverse-number
Reverse a Number in Python (5 Different Ways)
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › write-a-program-to-reverse-digits-of-a-number
Reverse Digits of a Number - GeeksforGeeks
After reversing, the string is converted back into a number. This method is simple and efficient but requires additional space for storing the string representation of the number. ... # Python 3 program to reverse a number def reversDigits(n): # converting number to string s = str(n) # reversing the string s = s[::-1] # converting string to integer n = int(s) # returning integer return n if __name__ == "__main__": n = 4562 print(reversDigits(n))
Published   April 3, 2026
🌐
EDUCBA
educba.com › home › software development › software development tutorials › python tutorial › reverse number in python
Reverse Number in Python | Top12 Methods of Reverse Number in Python
April 17, 2023 - Create a variable called reverse and initialize the variable value with 0. Now find the remainder for the given input number by using the mod (%) operator. Multiply the variable reverse with 10 and add the remainder value to it.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
WsCube Tech
wscubetech.com › resources › python › programs › reverse-number
Reverse a Number in Python (5 Different Ways)
October 29, 2025 - Explore 5 different ways to reverse a number in Python. Get step-by-step code examples, outputs, and clear explanations to enhance your understanding.
Find elsewhere
🌐
Tutorial Gateway
tutorialgateway.org › python-program-to-reverse-a-number
Python Program to Reverse a Number
April 7, 2025 - Number = int(input("Please Enter any Number: ")) Reverse = 0 while(Number > 0): Reminder = Number  Reverse = (Reverse *10) + Reminder Number = Number //10 print("\n Reverse of entered number is = %d" %Reverse) This program allows the user to enter any positive integer. Then, that number is assigned to a variable Number. Next, Condition in the Python While loop ensures that the given number is greater than 0.
🌐
Real Python
realpython.com › ref › builtin-functions › reversed
reversed() | Python’s Built-in Functions – Real Python
In your class, .__iter__() provides support for normal iteration, and .__reversed__() supports reverse iteration. ... In this step-by-step tutorial, you'll learn about Python's tools and techniques to work with lists in reverse order.
🌐
NxtWave
ccbp.in › blog › articles › reverse-a-number-in-python
Reverse a Number in Python: Methods & Best Practices
On the other hand, mathematical operations provide a more algorithmic approach to manipulating digits instead of converting the number to a string. In addition, Python has built-in options like the reversed() function or the use of list slicing, ...
🌐
Python Guides
pythonguides.com › reverse-a-number-in-python
How To Reverse A Number In Python?
March 20, 2025 - During code reviews at my previous position at a tech company in Austin, I often recommended this approach for its readability and use of Python’s built-in functions. ... from functools import reduce def reverse_number_functional(number): """ Reverse a number using functional programming.
🌐
Replit
replit.com › discover › how-to-reverse-a-number-in-python
How to reverse a number in Python
February 6, 2026 - Build and deploy software collaboratively with the power of AI without spending a second on setup.
🌐
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 - You can reverse a number in Python ... The simplest way is to use a for loop combined with slicing or the reversed() function to iterate through the digits in reverse and construct the reversed number....
🌐
Reddit
reddit.com › r/learnpython › can anyone explain how to reverse a integer number?
r/learnpython on Reddit: Can anyone explain how to reverse a integer number?
February 1, 2022 -

Sorry if that sound like stupid, I'm just a newbie to programming

At first I thought it was easy and started writing code and I find myself with bunch of errors.

Then I came up with this:

number = 12345
reverse = str(number)[::-1]
print(reverse)

It's just cheating you can say, I converted integer into string and made that string reverse.

After a while I thought, I'm just stupid to code like this but then later I googled and I found this solution which is more complicated to understand:

number = 12345

reverse = 0
while number > 0:
  last_digit = number % 10
  reverse = reverse * 10 + last_digit
  number = number // 10

print(reverse)

Can anyone please explain what's going on here?

🌐
Scaler
scaler.com › home › topics › reverse a number in python
Reverse a Number in Python - Scaler Topics
June 21, 2024 - In this method, we utilize the ... get reversed. So, we just add the digits of our number into a list using the list() function in Python, then use the reverse method on it to get the digits in reverse order and then by using the join() method, we obtain the final reversed ...
🌐
Edureka
edureka.co › blog › how-to-reverse-a-number
How to reverse a number in Python | Python Program Explained | Edureka
September 24, 2019 - There are two ways to reverse a number in Python programming language – ... # Get the number from user manually num = int(input("Enter your favourite number: ")) # Initiate value to null test_num = 0 # Check using while loop while(num>0): #Logic remainder = num % 10 test_num = (test_num * 10) + remainder num = num//10 # Display the result print("The reverse number is : {}".format(test_num))
🌐
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.
🌐
W3Schools
w3schools.com › python › ref_list_reverse.asp
Python List reverse() Method
The built-in function reversed() returns a reversed iterator object. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if ...
🌐
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 - A list reversal approach involves converting the integer into a list of its digits, reversing the order of the list, and then converting it back to an integer. This method utilizes Python’s built-in list manipulation capabilities, such as list() and reverse(), to efficiently reverse the digits.
🌐
PREP INSTA
prepinsta.com › home › python program › reverse a number in python
Reverse of a number in Python | PrepInsta​
July 29, 2023 - Let’s implement the above mentioned Logic in Python Language. ... num = 1234 temp = num reverse = 0 while num > 0: remainder = num % 10 reverse = (reverse * 10) + remainder num = num // 10 print(reverse) ... In this method we’ll use the string slicing methods to reverse the number.