Reverse a number(integer) in python | Loop or Recursion

Numbers can be reversed in Python using different methods. Like loop or Recursion can use to reverse a number in python. let us take a look at the Python program to implement the same.

Ways to reverse a number in Python

  • Using a Loop
  • Using Recursion

Python programs to reverse a number

Let’s see the both examples:

Reverse a Number(integer) using Loop

Example of reverse a user input Number using While loop:

Output:

Reverse a number(integer) in python

Reverse a Number(integer) using Recursion

Python Program to Reverse a user given Number using Recursion.

Output:

Reverse a Number(integer) using Recursion

Shortest Way

But it will not work with negative interger(numbers).

Output: 321

Do comment if you know any other method or doubts on this tutorial.

Note:
IDE: PyCharm 2020.1.1 (Community Edition)
macOS 10.15.4
Python 3.7
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.