5

Python Program to Reverse any Number

 1 year ago
source link: https://www.geeksforgeeks.org/videos/python-program-to-reverse-any-number/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Python Program to Reverse any Number

Python Program to Reverse any Number
Hey everyone. Welcome to Geeks
  • 90 Views
  • 14/06/2022

In this video, we will learn how to reverse a number using Python. We have divided this video into 4 parts.

Below is the list of approaches that we will cover in this video:

1. What is the prime number? 2. Iterative method to reverse a number 3. Recursive method to reverse a number 4. Inbuilt method to reverse a number 5. Using the stack method to reverse a number.

Reversing a number is a technique to reverse any number, i.e. 12345's reverse form will be 54321.

1. Iterative method to reverse a number: In this method, we will use a loop to reverse our number. Time complexity will be: O(n), and Auxiliary Space: O(1).

2. Recursive method to reverse a number: In this method, we will use recursion to reverse our given number. Time complexity will be: O(log(n)), and Auxiliary Space: O(log(n)).

3. Inbuilt method to reverse a number: In this method, we will use in build reverse() method, concatenation method, and Access List (lis [::]) method.

4. Using the stack method: In this method, we will use the stack, we will first push all the elements into the stack and then we will pop all the elements, as we know that stack works on LIFO the result we will get will be a reverse number.

Program to reverse digits of a number: https://www.geeksforgeeks.org/write-a-program-to-reverse-digits-of-a-number/


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK