1. 程式人生 > >python實現統計字符類型

python實現統計字符類型

串處理 [] app input def print for pri inpu

#字符串處理統計類型
def my_func(*str):
list_num = []
list_big = []
list_small = []
list_qt = []
str = input(‘請輸入一個字符串‘)
for j in str:
if ord(j) > 47 and ord(j) < 58:
list_num.append(j)
if ord(j) > 64 and ord(j) < 91:
list_big.append(j)
if ord(j) > 96 and ord(j) < 123:
list_small.append(j)
else:
list_qt.append(j)
a = len(list_big)
b = len(list_small)
c = len(list_num)
d = len(list_qt)
print(str) # 輸出一次你所輸入的字符串
print(‘大寫%d個,小寫%d個,數字%d個,其他%d個‘ % (a, b, c, d)) # 統計各類字符個數
list = [a, b, c, d]
print(tuple(list))
my_func()

python實現統計字符類型