以Python 3.x版本为主 统计次数:结合多个基础知识点,对字符串的每个字符进行次数统计 1、知识点 1)数组,定义和追加值 2)字符串,字符串变脸 3)find(),字符或字符串查找方法
以Python 3.x版本为主
统计次数:结合多个基础知识点,对字符串的每个字符进行次数统计
1、知识点
1)数组,定义和追加值
2)字符串,字符串变脸
3)find(),字符或字符串查找方法
4)if-else,逻辑判断
5)for,for循环
2、效果如下
2、代码如下
str='Hello World,Hello 51cto!'strNew=''
num=[]
for char in str:
index=strNew.find(char)
if index<0:
strNew+=char
num.append(1)
else:
num[index]+=1
for i in range(len(strNew)):
print("字符:%s,次数:%s" % (strNew[i],num[i]))