In this program, we will take a string as input and count occurrences of word in a string.
Steps to solve the program
- Take a string as input.
- Count the occurrences of a specified word in a string using count().
- Print the output.
#Input string
string1 = "I want to eat fast food"
#Printing output
print("Occurences of food: ",
string1.count("food"))
#Input string
string2 = "We are learning Python, wow are you"
#Printing output
print("Occurences of we: ",
string2.count("are"))
Output :
Occurences of food: 1
Occurences of we: 2