1 ''' 2 用Python方法辨別數據類型可以用python type()方法, 3 那么想要查看一串字符中每一項的類型, 4 並逐一輸出要怎么來處理呢? 5 6 Python練習題問題如下: 要求: 7 輸入一行字符,分別統計出其中英文字母、空格、數字和其它字符的個數。 8 9 ''' 10 s = input('輸入字符串:') 11 12 others = 0 13 space = 0 14 digit = 0 15 alpha = 0 16 17 for i in s: 18 if i.isdigit(): 19 digit += 1 20 elif i.isalpha(): 21 alpha += 1 22 elif i.isspace(): 23 space += 1 24 else: 25 others += 1 26 print(others,space,digit,alpha)