You can iterate a string in python, and you'll be iterating by each character

There you go:

a = input("Enter : ")
x = [num for num in a]  # Getting the individual digits
b = reversed(x)         # reversed() is a built in function
print("".join(b))
Answer from adsa on Stack Overflow
🌐
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 ...
🌐
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. ... This method converts the number to a string and reverses it by iterating through its characters. ... Explanation: The loop adds each character at the beginning of rev, forming the reversed order. Recursion works by repeatedly removing the last digit from the number and building the reversed number during the returning phase.
Discussions

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
How to write a program that reads a file and writes out a new file with the lines in reversed order (i.e. the first line in the old file becomes the last one in the new file.)
Here's another way: with open('textfile.txt') as rf, open('reversed.txt', 'w') as wf: for line in reversed(rf.readlines()): wf.write(line) with is a context manager that in the case of files, closes them when the context manager is finished. More on reddit.com
🌐 r/learnpython
8
1
May 17, 2017
How to do reverse word in python?
You can split your string into words with the split function, it splits on whitespace like so: "hello world".split() And then you can reverse the individual words. More on reddit.com
🌐 r/learnpython
28
0
October 4, 2017
Reversing a number
Hint: strings are reversible More on reddit.com
🌐 r/learnpython
9
2
September 17, 2020
People also ask

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)
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)
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)
🌐
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)
🌐
PREP INSTA
prepinsta.com › home › python program › reverse a number in python
Reverse of a number in Python | PrepInsta​
July 29, 2023 - ... 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.
🌐
Sanfoundry
sanfoundry.com › python-program-reverse-given-number
Python Program to Reverse a Number
June 21, 2023 - Let’s take a detailed look at all the approaches to reverse a number in Python. ... In this approach, we will divide the number by 10 and add the remainder to the sum. ... Here is the source code of the Python Program to reverse a given number.
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 ...
🌐
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.
🌐
Medium
medium.com › edureka › reverse-a-number-6eeb7eed0309
How to reverse a number in Python? | Edureka
February 4, 2021 - 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 RecursionNum = 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)
🌐
Python Guides
pythonguides.com › reverse-a-number-in-python
How To Reverse A Number In Python?
March 20, 2025 - The most simple way to reverse a number in Python is to convert it to a string, reverse the string, and convert it back to an integer: def reverse_number_string_method(number): """ Reverse a number using string conversion.
🌐
Django Central
djangocentral.com › reverse-a-number
Python Program To Reverse a Number
The algorithm below is used to ... = rev_num + (num) num = num // 10 print(rev_num) ... Python's built in reversed() method returns an iterator that accesses the given sequence in the reverse order....
🌐
w3resource
w3resource.com › python-exercises › basic › python-basic-1-exercise-30.php
Python: Reverse the digits of a given number and add it to the original - w3resource
... # Function to reverse a number and add it to the original number until a palindrome is obtained def rev_number(n): s = 0 # Initialize a variable to count the number of iterations while True: k = str(n) # Convert the number to a string for ...
🌐
CodeScracker
codescracker.com › python › program › python-program-find-reverse-of-number.htm
Python Program to Reverse a Number
Now supply the input say 236 as number, press ENTER key to find and print its reverse like shown in the snapshot given below: The dry run of above program with 236 as user input, goes like: When user enters the number say 236, it gets stored in num. So num=236 · The condition (of while loop) num!=0 or 236!=0 evaluates to be true, therefore program flow goes inside the loop and executes all the three statements present inside the block of this loop
🌐
Vultr
docs.vultr.com › python › examples › reverse-a-number
Python Program to Reverse a Number | Vultr Docs
December 9, 2024 - Reversing a number in Python can be achieved through multiple approaches, each with its unique style and use case. The string slicing method is the most straightforward for those familiar with Python's string operations.
🌐
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?

🌐
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 - Reverse operation in python can be defined as a process of turning the order of the input assigned to a variable from back to front or front to back. This operation can be achieved by any kind of logic involving the conditional statements of ...
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
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.
🌐
DataFlair
data-flair.training › blogs › python-program-on-reverse-a-number-using-recursion
Python Program on Reverse a Number Using Recursion - DataFlair
February 28, 2024 - I) Base case: If n <= 0, stop recurring II) Get last digit: r = n % 10 III) Append r to s: s = s * 10 + r ... 4. Return the global s which now contains the reversed number 5. Get user input for a number and store in n 6. Call reverse(n), store ...
🌐
YouTube
youtube.com › watch
Python Program to Reverse a Number ( using String Method Tutorial ) - YouTube
In this tutorial you will learn to Reverse a Number ( using String method ) in Python Programming language.We ask the user to enter a number and store it in ...
Published   September 10, 2020
🌐
OneCompiler
onecompiler.com › posts › 3z2wgtbha › python-program-to-reverse-a-number-with-explanation
Python program to reverse a number with explanation - Posts - OneCompiler
March 17, 2023 - In this tutorial we are going to learn how to write a program to reverse the digits of a given number in Python programming language. So Lets Begin: Before directly moving on the writing reverse program in C first you should understand the logic behind it. Suppose if someone gives input 123 ...