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(
Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3101] This PEP proposes a new system for built-in string formatting operations, intended as a replacement for the existing '%' string formatting operator. 1.百分号
一.重点掌握的6种字符串方法: 1.join命令 功能:用于合并,将字符串中的每一个元素按照指定分隔符进行拼接 程序举例: seq = ['1','2','3','4'] sep = '+' v = sep.join(seq) print(v) test = "学习要思考" t = '***' v = t.join(test) print(v) 2.split命令 功能:与join相反,将字符串拆分为序列 test = '1+2+3+4+5' v = test.split('+') p