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))
计算一个字符串中所有数字的和
最新推荐文章于 2024-08-22 10:11:20 发布