Python program to Select Integers from String

str = input("Insert strings with integer values: ") lenstr = len(str) mynum = [] x = 0 while x < lenstr: num = "" symbol = str[x] while '0' <= symbol <= '9': num += symbol x += 1 if x<lenstr: symbol = str[x] else: break x += 1 if num != "": mynum.append(int(num)) print(mynum)

 

 

Output:

Insert strings with integer values: string1253integer
[1253]

 

Insert strings with integer values: 12abc8972
[12, 8972]

Check simple Python projet with Rock paper scissors Game Python Source Code