In this program, we will take a string as input and extract numbers from a given string.
Steps to solve the program
- Take a string as input.
- Create an empty list.
- Split the given list using split().
- Use for loop to iterate over splitter string.
- If the value is a number then add it to the empty list.
- Print the output.
#Input string
str1 = "python 456 self learning 89"
list1 = []
for char in str1.split(" "):
if char.isdigit():
list1.append(int(char))
#Printing output
print(list1)
Output :
[456, 89]