统计传入字符串参数(可能不止一个参数)的英文字母、空格、数字和其他字符的个数

来源:互联网 发布:诱导源码 编辑:程序博客网 时间:2024/05/22 12:40
def count(*params):    length=len(params)    #字符串的个数    for i in range(length):       letter=0       num=0       space=0       others=0           for each in params[i]:#每个字符串中国的参数            if each.isalpha():                 letter +=1            elif each.isdigit():                 num +=1            elif each==' ':                 space +=1            else:                 others +=1       print('第%d个字符串中参数有:%d 个英文字母,数字%d个,空格%d个,%d个其他字符'%(i+1,letter,num,space,others))count('hello world','我的 的的 123')

阅读全文
0 0
原创粉丝点击