count number of spaces in string python

Do you want to know the information about “count number of spaces in string python”. If yes, you’re in the correct tutorial.

count number of spaces in string python

# '.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'

Conclusion

I hope this tutorial helps you to know about “count number of spaces in string python”. If you have any doubts regarding this tutorial please let us know via the comment section. Share this article with your friends & family via social networks.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coder Diksha. Here, I post about programming to help developers.

Share on:

Leave a Comment