Skip to content

Python code snippet – How to count the occurrence of a word in string ?

# define string
string = "Python is awesome, isn't it?"
substring = "is"

count = string.count(substring)

# print count
print("The count is:", count)
See also  Python code snippet - How to create and save augmented images?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.