输入一个字符串,要求在这个字符串中大写字母,小写字母,数字,其他字符共出现了多少次

str = 'LiKeYou960415'
cl = 0 #计数大写字母个数
lc = 0 #计数小写字母个数
num = 0 #计数数字个数
i = 0 #遍历字符串中所有的元素
while i < len(str): #判断是否遍历完毕,len()是统计字符串的字长
if str[i].isupper(): #判断当前是否是大写字母
cl += 1 #计数
elif str[i].islower(): #判断是否是小写字母
lc += 1 #计数
elif str[i].isdigit(): #判断当前是否是数字
num += 1 #计数
i += 1 #遍历字符串
print('大写:', cl)
print('小写:', lc)
print('数字:', num)

原文地址:https://www.cnblogs.com/g15009428458/p/11461189.html