Python program to Count Total Characters in a String

string = "The best of programming ";
count = 0;
#Counts each character except space
for i in range(0, len(string)):
    if(string[i] != ' '):
        count = count + 1;
print("Total number of characters in a string: " + str(count))

OUTPUT:

Total number of characters in a string: 20

Leave a Comment