19
a = input("Enter the string paragraph:")
count = 0
for c in a:
    if c == " ":
        count += 1
        print("Number of spaces in a string:", count)

How do I count the number of spaces?

Neuron
  • 5,141
  • 5
  • 38
  • 59
Myscript
  • 191
  • 1
  • 1
  • 6
  • My question is simple, User has entered the set of character or string , Eg: I a m in the cof fe e sh op. So I wanted to count number of space in the full user input. So totally there are 8 space. and I also want to print at which all position the space is ... – Myscript Nov 23 '15 at 06:16

1 Answers1

32
>>> a=input("Enter the value ")
Enter the value "My Testing String"
>>> a.count(' ')
2
Mayur Koshti
  • 1,794
  • 15
  • 20