def numsum(s): sum = 0 # 定义变量,准备记录数字的和 for i in range(len(s)): # 遍历字符串 try: sum = sum + float(s[i]) # 将字符转成int,求和 except: continue return sumnum(s=[1, 2, 3])