1.默认字符串中只有小写字母和数字 2.数字可能连续,也可能不连续 3.连续数字要当做一个数处理
如:'12abc34de5f' => 12 + 34 + 5 => 51
def sum_of_num(s): num =0 he=0 for i in s: if i.isdecimal(): n=int(i) num=num*10+n else: he+=num num=0 he+=num return he
# s = '123abc34de5f' # print(sum_of_num(s))
结果:192