Extract numbers from a given string

In this program, we will take a string as input and extract numbers from a given string.

Steps to solve the program
  1. Take a string as input.
  2. Create an empty list.
  3. Split the given list using split().
  4. Use for loop to iterate over splitter string.
  5. If the value is a number then add it to the empty list.
  6. 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]
				
			

find the string similarity between two given strings

split a given multiline string into a list of lines

Leave a Comment