第二题:计算字符串中所有数字的和1.字符串中只有小写字母和数字2.数字可能连续,也可能不连续3.连续数字要当做一个数处s='1234adg3g11's1 = "" for i in s : if i.isdigit(): s1=s1+i else: s1=s1+" " lt = s1.split(" ") m= 0 for a in lt : if a.isdigit(): m=m+int(a) print(m) *解决思想:把字符串中得数字调出…
#统计字符串中每个字符出现的次数 以The quick brown fox jumps over the lazy dog为例 message='The quick brown fox jumps over the lazy dog' count={} for character in message: count.setdefault(character,0) count[character]=count[character]+1 print(count) 参考:<Python编程快速上手--…