Project Description
Your task for today is to write a Python program that extracts all the digits from a given string and stores them in a list.
Start with a string stored in a variable. For example:
text = "The year is 2025 and the time is 09:45."
Your program should scan this string character by character and collect all the digits.
Expected Output
The program should print out a list containing only the digits from the string. For example:
['2', '0', '2', '5', '0', '9', '4', '5']
💡 Hint
Don’t know where to start? This hint will show you how to begin.
𝌣 Solution
🔒 This solution is available to paid subscribers only.
🚀 Want to keep leveling up?
Browse 200+ projects at dailypythonprojects.substack.com/archive and unlock all solutions by subscribing. Build real Python skills daily and transform how you learn — one project at a time.
print( [i for i in text if i.isnumeric()] )
#Extract All Digits From a String in Python
text = "The year is 2025 and the time is 09:45."
num = []
for i in text:
if i.isdigit():
num += i
print(num)