How to extract digits from a number from left to right?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to extract digits from a number from left to right in Python. So Here I am Explain to you all the possible Methods here.

How to extract digits from a number from left to right?

1. How to extract digits from a number from left to right?

If you don't have problem with recursion approach then here is a solution with little change in your code:-
def get_digit(num): if num < 10:

2. extract digits from a number from left to right

If you don't have problem with recursion approach then here is a solution with little change in your code:-
def get_digit(num): if num < 10:

Method 1

If you don’t have problem with recursion approach then here is a solution with little change in your code:-

def get_digit(num):
if num < 10:
print(num)
else:
get_digit(num // 10)
print(num % 10)

Usage

>>> get_digit(543267)
5
4
3
2
6
7

Method 2

You can do something like this.

number = 122322
num_str = str(number)
for num in num_str:
print num

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.