此问题已经在这里有了答案:
a=input("Enter the value ") for i in a: if a[i]==(" "): print("Space is at position", i)
我正在尝试计算给定字符串中的空格数,但是我的程序无法正常工作。
>>> a=input("Enter the value ") Enter the value "My Testing String" >>> a.count(' ') 2