Summay: In this Python tutorial, you will learn to reverse a given number using Python programming language.

Reversing a number means to change the order of the digits of the given number. For example, reverse of ‘12345’ is ‘54321’.

In Python, we can easily reverse a number by following the below steps.

  1. Input a number.
  2. Run while loop with condition number>0
  3. Add the last digit of the number to the reverse i.e. reverse = reverse*10 + number%10.
  4. Remove the last digit from number i.e. number = number/10

Here is the implementation of the above steps in Python:

#Reverse Number in Python

print("Enter a Number \n")
num = int(input())
rev = 0
while num > 0:
    rev = (rev*10) + (num %10);
    num = num//10
print("Reverse is: %d " %rev)


Reverse a number in Python

That’s all we need to write in python to reverse a number. If you still need someone to assist you, we recommend AssignmentCore to get Python programming homework help from experts. If you have any doubts, then comment below. 

This Post Has 3 Comments

  1. mithila

    num = num //10
    why is this double slash is required ? what does it mean?

    1. Adarsh Kumar

      ‘/’ is division operator whereas ‘//’ is floor division operator.

      3/2 = 1.5
      3//2 = 1

      1. mithila

        thank u

Leave a Reply