首页 > 代码库 > 计算字符串中al_num,spance_num,digit_num,other_num的个数

计算字符串中al_num,spance_num,digit_num,other_num的个数

 1 def jisuan(x) :
 2     al_num = 0
 3     spance_num = 0
 4     digit_num = 0
 5     other_num = 0
 6     for i in x :
 7         if i.isdigit() :
 8             digit_num += 1
 9         elif i.isspace() :
10             spance_num += 1
11         elif i.isalpha() :
12             al_num += 1
13         else :
14             other_num += 1
15     return (al_num,spance_num,digit_num,other_num)
16 
17 
18 r= jisuan("qwerrwqrqrwqr erwqrdsfdad#sfa")
19 
20 print(r)

 

计算字符串中al_num,spance_num,digit_num,other_num的个数