In this tutorial we will be knowing how to reverse a given number using Python.
First, let us take a variable and assign a any number with multiple digits to it.
Eg: num=12345
then take another variable, rev_num and assign [0] to it.
E.g. rev_num=0
then take a while loop to perform next step.
E.g: while num!=0
Now, the complete code is here.
num=12345 rev_num=0 while num!=0: digit=num%10 rev_num=rev_num*10+digit num//=10 print(str(rev_num))
output:
54321