Count occurrences of word in a string.

In this program, we will take a string as input and count occurrences of word in a string.

Steps to solve the program
  1. Take a string as input.
  2. Count the occurrences of a specified word in a string using count().
  3. 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
				
			

find the location of a word in a string

find the least frequent character in a string.

Leave a Comment