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