line = input("> ") L = len(line) for i in range(L): if not line[i].isdigit(): continue digitstring = line[i] i = i+1 while line[i].isdigit(): digitstring = digitstring + line[i] i = i + 1 print(digitstring)