如何在Python中计算给定字符串中的空格数

Mys*_*ipt 7 python

a=input("Enter the value  ")

for i in a:
  if a[i]==(" "):
       print("Space is at position", i)
Run Code Online (Sandbox Code Playgroud)

我正在尝试计算给定字符串中的空格数,但是我的程序无法正常工作。

May*_*hti 8

>>> a=input("Enter the value ")
Enter the value "My Testing String"
>>> a.count(' ')
2
Run Code Online (Sandbox Code Playgroud)