def char_count(string):
len1 = len(string);
count = 0;
for i in range(len1):
x=ord(string[i]);
if ((x>=65 and x<=90) or (x>=97 and x<=122) or (x>=49 and x<=57)):
count += 1;
return count;
str1=input('请输入字符串');
print(char_count(str1));
统计字符串中字母和数字的个数,将总个数返回
最新推荐文章于 2024-05-08 17:03:28 发布