统计字符串中出现的字母,数字,空格的次数
def countstr(*parm):length=len(parm)
for i in range(length):
zm=0
kg=0
sz=0
other=0
for each in parm:
if each.isalpha():
zm+=1
elif each.isspace():
kg+=1
elif each.isdigit():
sz+=1
else:
other+=1
print('第%d个字符串共有%d个字母%d个空格%d个数字%d个其他'%((i+1),zm,kg,sz,other))
countstr('hshhggd','fdfs 22@') a='aaa 1'
for i in a:
if i.isdigit():
num=a.count(i)
elif i.isspace():
num1=a.count(i)
print(num,num1)
页:
[1]