迭代 判断数字 累加器

s20 = "I am sylar, I'm 14 years old, I have 2 dogs!"
count = 0
for c in s20:            # 迭代器 if 变量 in可迭代的对象
if c.isdigit():
# count = count + 1
# print(count) # 检查里面有几个数字




for c in s20:
if c.isdigit(): # if c.isdigit # 判断是不是数字 if c.isdigit()

count = count + int(c)    # 累加器,---注意str变int型, 用int() count= count+int()
print(count)             
原文地址:https://www.cnblogs.com/jack20181017/p/9851324.html