How to count digits, letters, spaces for a string in Python?

前端 未结 9 1423
忘了有多久
忘了有多久 2020-12-01 08:14

I am trying to make a function to detect how many digits, letter, spaces, and others for a string.

Here\'s what I have so far:

def count(x):
    leng         


        
9条回答
  •  忘掉有多难
    2020-12-01 08:23

    There are 2 errors is this code:

    1) You should remove this line, as it will reqrite x to an empty list:

    x = []
    

    2) In the first "if" statement, you should indent the "letter += 1" statement, like:

    if x[i].isalpha():
        letters += 1
    

提交回复
热议问题