python 获取字符串中所有数字
s = "dede323frf54de23" l = len(s) numbers = [] i = 0 while i < l: num = '' symbol = s[i] while '0' <= symbol <= '9': # symbol.isdigit() num += symbol i += 1 if i < l: symbol = s[i] else: break i += 1 if num != '': numbers.append(int(num)) print(numbers)
输出:
[323, 54, 23]