判断一个字符串中得大写字母,小写字母,数字出现得次数


def Count_str(s):
    if len(s) ==0 :
        return 0,0,0,0
    upper_num,lower_num, number_num,other_num = 0,0,0,0
    for i in s:
        if i.isupper():
            upper_num += 1
        elif i.islower():
            lower_num += 1
        elif i.isdigit():
            number_num += 1
        else:
            other_num += 1
    return upper_num,lower_num,number_num,other_num

s = input("请输入你想要输入得字符串:")
n1,n2,n3,n4 = Count_str(s)
print(f"大写字母有{n1}个,小写字母有{n2}个,数字有{n3}个,其他字符有{n4}个")```

猜你喜欢

转载自www.cnblogs.com/ainimore/p/12902389.html