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
Answer from AlokThakur on Stack Overflow
๐ŸŒ
Medium
medium.com โ€บ @alopezmartinez โ€บ extracting-digits-from-an-integer-in-python-a-step-by-step-guide-96c9ff98db37
Extracting Digits from an Integer in Python: A Step-by-Step Guide | by AmericaML | Medium
August 6, 2024 - Step 1 โ€” Isolate Rightmost Digits:number % 10 ** digit_index: This isolates the rightmost digit_index digits. For digit_index = 3, this gives us the last three digits of 5678, which is 678.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-extract-digits-from-given-string
Python - Extract digits from given string - GeeksforGeeks
July 11, 2025 - Explanation: We loop through each ... is printed as the result. Using re.findall() in Python allows to extract all substrings that match a specific pattern such as digits, from a given string....
๐ŸŒ
YouTube
youtube.com โ€บ watch
How To extract the digits of a number in Python - YouTube
In this video we will learn how to extract the digits of a number, combine modulo and division in Python. Please Subscribe to Asim Code.Code: https://github...
Published: April 24, 2022
๐ŸŒ
AskPython
askpython.com โ€บ python โ€บ string โ€บ extract-digits-from-python-string
2 Easy Ways to Extract Digits from a Python String - AskPython
May 5, 2026 - For ASCII-only digits, you can check '0' <= char <= '9' instead. Pythonโ€™s regular expression module handles digit extraction with the pattern \d+, which matches one or more consecutive digit characters.
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-how-to-extract-and-reorder-number-digits-437621
How to extract and reorder number digits | LabEx
This tutorial explores comprehensive techniques to break down numeric values, extract individual digits, and perform complex reordering operations using Python's powerful string and numeric processing capabilities.
Find elsewhere
๐ŸŒ
Tutorial Reference
tutorialreference.com โ€บ python โ€บ examples โ€บ faq โ€บ python-how-to-extract-first-digit-of-number
How to Extract Digits from Numbers and Strings in Python | Tutorial Reference
March 29, 2025 - The simplest way to get the first digit of an integer is to convert it to a string and access the first character: ... The str() function transforms the integer into a string, which is then accessed using the index 0.
๐ŸŒ
IncludeHelp
includehelp.com โ€บ python โ€บ extract-and-print-digits-in-reverse-order-of-a-number.aspx
Extract and print digits in reverse order of a number in Python
So, in the following problem, we are going to use the mathematical trick of: Subtracting the remainder after dividing it by 10 i.e. eliminating the last digit. Dividing an integer by 10 gives up an integer in computer programming (the above statement is only true when the variables are initialized ...
๐ŸŒ
Finxter
blog.finxter.com โ€บ 5-best-ways-to-extract-specific-digits-from-numbers-in-a-python-list
5 Best Ways to Extract Specific Digits from Numbers in a Python List โ€“ Be on the Right Side of Change
The lambda function is used as a predicate to return False if the specific digit is not in the number. The filterfalse returns an iterator which is then converted to a list to get the filtered numbers. Pythonโ€™s functional programming constructs can also be applied to this problem.
๐ŸŒ
YouTube
youtube.com โ€บ code with tj
Write a Python Program to Extract Each Digit From an Integer in The Reverse Order - YouTube
Hello Programmers, Welcome to my channel.In this video you will learn about how to Write a Python Program to Extract Each Digit From an Integer in The Revers...
Published: June 6, 2023
Views: 379
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-extract-rear-k-digits-from-numbers
Python - Extract Rear K digits from Numbers - GeeksforGeeks
July 23, 2025 - In this, we perform task of getting rear elements using list slicing, and str() is used to convert each element to string. ... # Python3 code to demonstrate working of # Extract Rear K digits from Numbers # Using str() + slicing # initializing list test_list = [5645, 23567, 34543, 87652, 2342] # printing original list print("The original list is : " + str(test_list)) # initializing K K = 3 # getting integer using int() after slicing string res = [int(str(idx)[-K:]) for idx in test_list] # printing result print("Rear K digits of elements ?
๐ŸŒ
Replit
replit.com โ€บ discover โ€บ how-to-extract-digits-from-a-number-in-python
Discover | Replit
March 10, 2026 - Describe what you want. Replit builds it. Get a working app or website in minutes. No coding required.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-extract-numbers-from-string
Python | Extract Numbers from String - GeeksforGeeks
September 16, 2024 - Sometimes, while working with Python strings, we can have a problem in which we have to perform the task of extracting numbers in strings that are enclosed in brackets. Let's discuss the certain ways in which this task can be performed. Method 1: Using regex The way to solve this task is to construc ยท 6 min read Python - Extract Rear K digits from Numbers
๐ŸŒ
Quora
quora.com โ€บ How-can-I-access-individual-digits-in-a-multi-digit-number-in-Python
How to access individual digits in a multi-digit number in Python - Quora
Answer (1 of 14): Iโ€™m assuming this is a homework assignment and as a matter of principal I wonโ€™t do your homework for you as that will ruin any chance of your learning something from the assignment. So, if you were hoping for a complete solution here, prepare to be disappointed.
๐ŸŒ
w3resource
w3resource.com โ€บ python-exercises โ€บ string โ€บ python-data-type-string-exercise-93.php
Python: Extract numbers from a given string - w3resource
June 12, 2025 - ... # Define a function to extract numbers from a given string def test(str1): # Use a list comprehension to extract integers from the string if they are digits result = [int(str1) for str1 in str1.split() if str1.isdigit()] # Return the list ...
๐ŸŒ
CodingTechRoom
codingtechroom.com โ€บ question โ€บ extract-each-digit-from-integer-python
How to Extract Each Digit from an Integer in Python? - CodingTechRoom
number = 12345 # Convert integer to string and iterate through each character digits = [int(digit) for digit in str(number)] In Python, extracting each digit from an integer can be accomplished using various methods, including string manipulation, ...
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-extract-rightmost-digit-in-python-302739
Python Programming | Digit Extraction | Problem-Solving | LabEx
def f(n, k): """ Return the k-th digit of the integer n from the right. Args: n (int): The integer. k (int): The position of the digit from the right. Returns: int: The k-th digit from the right. """ ## Convert n to a string n_str = str(n) ## Get the k-th digit from the right k_digit = int(n_str[-k]) return k_digit