count number of spaces in string python
>>> a = "My test string"
>>> a.count(' ')
2
3.5
6
# '.isspace() ' return True of False for if a character is a space
word = "How many spaces"
num = 0
for i in word:
if(i.isspace() == True):
num += 1
print(num) #Output: '2'
Thank you!
6
0
Are there any code examples left?
New code examples in category Python