+ 1

Counting number of letters in string without spaces count

How you can count the number of letters in string without counting spaces? I tried with for loop but it counting spaces as well. Anyone help please

30th Apr 2021, 10:07 AM
Jitendra
Jitendra - avatar
3 odpowiedzi
+ 5
there is a very simple method to do this: (if you assume that everything except space is a letter) ▪︎as a sample: text = 'How are you?' ▪︎get length (=number of total characters) of the string by using len(text) ▪︎ get number of spaces by using text.count(' ') ▪︎ subtract number of spaces from total length you can do this with one line of code ! happy coding !
30th Apr 2021, 1:49 PM
Lothar
Lothar - avatar
+ 1
Try using isalpha() Google how to use it
30th Apr 2021, 11:13 AM
Rik Wittkopp
Rik Wittkopp - avatar
0
You can try with any letters in string, just need code for total counts of letter in string. For instance, check this one by me. But it counts spaces as well and gives output 12 including 9 letters with 3 spaces #code text = 'How are you?' count = 0 for i in text: count+=1 print(count)
30th Apr 2021, 10:51 AM
Jitendra
Jitendra - avatar