字符串--统计个数
输入一行非中文字符,分别统计出其中英文字母、空格、数字和其他字符的个数
def countzimu(): dict = {} shuzi = 0 zimu = 0 space = 0 other = 0 str = input("请输入任意字符:") for i in str: if i.isdigit(): shuzi+=1 elif i.isalpha(): zimu+=1 elif i.isspace(): space+=1 else: other+=1 dict['shuzi'] = shuzi dict['zimu'] = zimu dict['space'] = space dict['other'] = other return dict print(countzimu())
上班求生存,下班求发展