>>> word = "dog"
>>> str1 = "the dogs barked"
>>> sum(i == word for word in str1.split())
0
>>> word = 'dog'
>>> str1 = 'the dog barked'
>>> sum(i == word for word in str1.split())
1
참조:
https://stackoverflow.com/questions/17268958/finding-occurrences-of-a-word-in-a-string-in-python-3