Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
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
asked Feb 18, 2021 in Python by Harsh (1.5k points)
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
asked Oct 30, 2020 in Python by Sudhir_1997 (55.6k points)
0 votes
1 answer
asked Oct 14, 2019 in Python by Sammy (47.6k points)

Browse Categories

...