Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Python by (50.2k points)
Can anyone tell me how to reverse a number in Python?

1 Answer

0 votes
by (108k points)

To reverse a number in Python, you have to traverse the number and perform the below code:

n=1385

reverse = 0

while(n > 0): 

    a = n % 10

    reverse = reverse * 10 + a 

    n = n // 10

print("The reverse is: ",reverse)

The output:

The reverse is:  5831

If you are looking for an online course to learn Python, I recommend this Python Course by Intellipaat.

Related questions

0 votes
0 answers
0 votes
1 answer
asked Jul 11, 2020 in Python by ashely (50.2k points)
0 votes
1 answer
asked Jul 9, 2020 in Python by ashely (50.2k points)
0 votes
1 answer
0 votes
1 answer
asked Oct 30, 2020 in Python by Sudhir_1997 (55.5k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.6k users

Browse Categories

...