統計一串字元中字母 數字 空格和其他字元出現的次數

2021-10-10 06:51:34 字數 804 閱讀 2385

while

true

:str

=input

("請輸入字串:"

) alp =

0 spa =

0 num =

0 oth =0if

strin

'nn'

:break

else

:for c in

str:

if c ==

' ':

spa = spa +

1continue

if'a'

<= c.lower(

)<=

'z':

alp = alp +

1continue

if'0'

<= c <=

'9':

num = num +

1continue

else

: oth = oth +

1print

("該字串中字母的數目為:{}"

.format

(alp)

)print

("該字串中數字的數目為:{}"

.format

(num)

)print

("該字串中空格的數目為:{}"

.format

(spa)

)print

("該字串中其他字元的數目為:{}"

.format

(oth)

)

css一串純數字或純英文無空格的字串強制換行

spanwhite space normal pre nowrap pre wrap pre line inherit white space 屬性設定如何處理元素內的空白 normal 預設。空白會被瀏覽器忽略。pre 空白會被瀏覽器保留。其行為方式類似 html 中的 pre 標籤。nowrap...

python 如何判斷字串中數字和字母

isdigit 嚴格解析 有除了數字或者字母外的符號 如空格,分號,etc.都會false isalnum 必須是數字和字母的混合 isalpha 不區分大小寫 demo str 1 123 str 2 abc str 3 123abc 用isdigit 函式判斷是否數字,比較常用 print st...

統計一條語句中的空格 字母 數字的個數

include方案一 int main printf space count d n space count printf letter count d n letter count printf num count d n num count return 0 總結 想要統計字元,數字和空格的數量...